Passing SAFEARRAY of UDTs to a COM object

Hi there,
I am trying to interface with a legacy COM application from a Java client using
jCOM. One of the methods of the COM program takes an input which is a VARIANT
containg a SAFEARRAY of a custom type. The custom type is a simple structure
consisting of two 'doubles'.
The relevant bits of the IDL file looks like this (reverse engineered using OLEView):
uuid(19CFAB24-06AC-11D7-9C30-0050DA7B5DE3),
version(1.0),
helpstring("XXX 1.0 Type Library")
library XxxLib
// TLib : // TLib : OLE Automation : {00020430-0000-0000-C000-000000000046}
importlib("stdole2.tlb");
// Forward declare all types defined in this typelib
interface IXxx;
typedef [uuid(2EC68D72-0780-11D7-9C31-0050DA7B5DE3), helpstring("UNNAMED_POINT
struct")]
struct tagUNNAMED_POINT {
double latitude;
double longitude;
} UNNAMED_POINT;
uuid(19CFAB31-06AC-11D7-9C30-0050DA7B5DE3),
helpstring("Xxx Class")
coclass Xxx {
[default] interface IXxx;
odl,
uuid(19CFAB30-06AC-11D7-9C30-0050DA7B5DE3),
helpstring("IXxx Interface")
interface IXxx : IUnknown {
[helpstring("Set the points for a line symbol on the named overlay")]
HRESULT _stdcall SetLineSymbol(
[in] BSTR display_name,
[in] BSTR line_type,
[in] BSTR overlay_name,
[in] VARIANT points);
The parameter 'VARIANT points' is a SAFEARRAY containing an array of UNNAMED_POINTs.
The problem I am having is that the COM client returns COM error 0x80070057 -
Invalid arguments. Unfortunately I do not have access to the COM source code.
I have, however, tried creating a test utility with the same function prototype
so that I can debug it in Visual Studio. This shows that the VARIANT is being
sent correctly as a SAFEARRAY with the correct number of elements but the contents
of it are rubbish.
Has anyone else had this problem, or is there a way round it? We have accessed
the COM object successfully from a C++ client.
Thanks in advance,
Tim

Assuming you have the pieces of information that need to go into the array, convert each one into a variant using the built-in LV function. Next, combine all the resulting variants into an array using an array builder. Finally wire the array of variants to the com object terminal where you need it.
Mike...
Certified Professional Instructor
Certified LabVIEW Architect
LabVIEW Champion
"... after all, He's not a tame lion..."
Be thinking ahead and mark your dance card for NI Week 2015 now: TS 6139 - Object Oriented First Steps

Similar Messages

  • Pass a COM object across processes

    Hi,
    I need to pass a COM object from process A to B.  I didn't find a good code example for IMoniker.  So I am trying to test a simpler solution.  Please refer to the following snippet of code.  There is a problem.  When the execution
    reaches GetActiveObject in B, the system hangs.  "HRESULT h" in several places returns S_OK.   Does anybody have a clue?  Please help me out.  Thanks for your help in advance.
    // the definition of the COM object
    EXTERN_C const IID IID_IUniverse;
    #if defined(__cplusplus) && !defined(CINTERFACE)
        MIDL_INTERFACE("91CAF3F6-BD4D-4DDC-9C35-59F5DB20D570")
        IUniverse : public IDispatch
        public:
    // PROCESS A:
    HRESULT h = RegisterActiveObject (cwApp, IID_IUniverse, ACTIVEOBJECT_STRONG , &dwRegister);
    // PROCESS B:
    HRESULT h = CoInitialize(NULL);
    IUniverse *p = NULL;
    HRESULT h = GetActiveObject(IID_IUniverse, NULL, (IUnknown**)&p);
    if (p)
      CComPtr<IUniverse> cwApp(p);
    JD

    On 1/27/2015 7:43 PM, jdyng77 wrote:
    I did some research on this issue to help me better understand your comments here.  I still don't fully understand the problem.  Please help me out.  Or, if I can get around the problem by using IMoniker and IRunningObjectTable instead,
    I would be more than happy doing that.
    Unlikely. If, as I suspect, the problem is that the server thread blocks, then the client won't be able to obtain the interface pointer from it by any means. Any IPC mechanism you might want to use kind of assumes that both parties remain responsive.
    WaitForSingleObject() is the opposite of "responsive".
    The third party (3rd pty) provides a COM interface.  I write a COM server A
    In-process (a DLL) or out-of-process (an EXE)? From your description, I would assume in-proc.
    that has an implementation for this interface.  I believe the 3rd pty must have called CoInitialize(NULL) before it instantiates object A.
    It must have, yes. This is only significant if A is an in-proc server.
    The 3rd pty passes a COM object of IUniverse to A.  I can call IUniverse's methods in A without any problem.  The need here is to transfer the IUniverse object to another process B so that B can call IUniverse's methods.  The problem
    is that B hangs.
    My guess is, B hangs because A hangs. In one of your responses, you suggest that you are calling WaitForSingleObject (waiting on process B's handle, I presume). In so doing, you have created a deadlock. B is trying to communicate with A to retrieve the
    interface pointer, but A is waiting for B to exit.
    After A registers IUniverse pointer (whether in ROT or as active object), it should return to the caller. Said caller likely spins a message pump - but by blocking and not returning, you don't allow it to run.
    The thread where A sits is created in the 3rd pty.  If I understand you correctly, the 3rd pty must "retrieve and dispatch window messages in a timely manner".  I think it does because it calls A when a window button is clicked.
    3rd pty would, if only A would let it. By sitting in the message handler, A prevents the caller from retrieving messages in a timely manner.
    But I don't know whether I should use Class, File or Item IMoniker.
    Item moniker is the easiest to use by far. It just wraps a piece of text. You create one with CreateItemMoniker: pass L"!" (by convention) in the first parameter, and arbitrary string in the second. Both parties (one that registers in ROT, and
    one that picks up) should agree on and use the same string, of course.
    Igor Tandetnik

  • How do I pass a com object to a callback function

    I am trying to program the PCI-6527 card within a COM object. With the DIG_Change_Message_Config command I'm setting the notification for when the input signal changes using a callback function. To make the callback function work I have to declare that function as a static member of the object class. This means that I have no access to the this pointer in this function. After I receive the notification, my actions in the callback function depend on settings in member variables in the class. MSDN gives as a solution to pass the this pointer as an argument to a static member function to have access to the class. I've tried this but the compiler keeps barfing at me.
    The code used is:
    stat = DIG_Change_Message_Config(
    m_CardNum,1, msg,"",0,0, (unsigned long)DealWithInput );
    with DealWithInput defined as: static void DealWithInput();
    Is there a way of getting access to the class in DealWithInput either by passing it as an parameter or through some other ingenous trick that I can't find documentation for

    The thing is that you cannot change the parameters of the callback functions. It is always :
    void yourCallbackFunc (DAQEventHandle handle,
    DAQEventMsg msg,
    DAQEventWParam wParam,
    DAQEventLParam lParam);
    When yourCallbackFunc is called back, all the parameters get filled in the calling function in DAQ driver. What you have to do is pass the this pointer in message parameter in DIG_Change_Message_Config function, so that whatever you pass in message gets passed back in your callback function. Message can be any type.

  • Passing SAFEARRAY Pointer from CVI

    Hi,
    I am having problem in importing IVI-COM dll to C wrapper dll in Labwindows/CVI. I have to do that for my TestStand application to call the functions of the dll. After registering the COM dll, I have used �Create Activex Controller� option to create .c, .fp and .h files. With this, I was able to create dll but without any prototype info. So, I included the fp file to include prototype info. But while I create my dll with the type lib info, odl file gave error to use SAFEARRAY pointer. So I have declared a structure mySAFEARRAY (same parameters as that of SAFEARRAY) and has replaced all the (SAFEARRAY *) to (mySAFEARRAY *). After doing this, I have created the dll successfully.
    Now in TestStand when I have called the dl
    l with �Flexible Prototype Adapter�, few of the data types (structures) are not applicable to TestStand. So it is taking all the unknown data types to �long�. When I check the prototype with my C file, it is telling mismatch prototype.
    Now, please help me what do we do for the C wrapper dll to work proper. Is the procedure (which I have described above) proper?
    I have got one info from NI site, that the functions using the structure parameters should not be exported directly. Instead a wrapper function should be created, with each and every element of the structure as it parameter. Now do we create a wrapper function for each and every function which has the structure parameter in it? I am eagerly waiting for your information. Actually i am new to both CVI and TestStand.
    Thank you in advance for your help.
    Thank you,
    Sasi.

    Hello Sasi -
    I am uncertain what your situation is, but it sounds like you are trying to pass the SafeArray as a parameter of your DLL back to TestStand? TestStand only recognizes certain known types when it comes to creating new memory to hold variables. A SafeArray is fundamentally an array of objects, so passing it directly to TestStand is unlikely to work. Your best bet is to look into the LabWindows/CVI examples and functions for converting SafeArrays to one-dimensional arrays of numbers, and passing that array back to TestStand via a parameter or some API call.
    As an additional note, there are generic examples of how to successfully pass structures back and forth between TestStand and code modules, but it requires both environments having a definition o
    f the structure as well as agreeing upon the byte-packing of the data. The best resource I can provide is to point you to the TestStand shipping example located in the /Examples/Struct Passing/ directory. However depending on how you are attempting to extract that SafeArray, this may not be an issue (as far as writing a numeric array vs. writing a structure).
    If this doesn't help answer your question, maybe you can give me a little more information, maybe a function declaration for your code, to try and see what you are doing in more detail?
    --Regards
    Elaine R.
    National Instruments
    http://www.ni.com/ask

  • How can I call a COM object from a PL/SQL CODE

    Hi everyone,
    Does anyone know how to call a COM object from a stored procedure in oracle.
    a sample of code
    please help,
    Hilaire

    Are you familiar with external procedures? Basically, you can expose functions exported by a shared library (i.e. a DLL on Windows) to the Oracle database. My assumption is that you'd probably need to write a wrapper DLL around the COM object, since I believe you can only pass fundamental data types back and forth (i.e. no object references). You'd expose the method(s) of that wrapper DLL to the database via external procedures.
    Justin
    Distributed Database Consulting, Inc.
    www.ddbcinc.com/askDDBC

  • COM object that has been seperated from its uderlying RCW cannot be used

    What exactly does this error mean?
    I receive this error when I perform "Unload All Modules" from the sequence editor using TestStand 4.2.1.83 development system, which is part of NI Developer Suite 2010 DS1.
    It causes TestStand to crash citing that error, and then a secondary error cites corrupted memory.

    ATE_Dude_22 wrote:
    Here is a capture of my sequence editor, where I have a alert from TestStand telling me the parameter specified doesn't match the sequence parameters (specified in the vi prototype as a string not a number), but this version of TestStand allows it to execute without needing to clear the error.
    Do you think this may have anything to do with the error I am seeing?
    Probably not. Sequence calls support mismatched parameters, what happens is that the callee gets whatever is passed to it, if that's not what it's expecting, then you might get a type mismatch error if type checking is enabled, if not then it's up to the sequence what it tries to do with the parameter for what happens next.
    Most likely the bug is in one of the code modules you are calling, probably a vi or dll is not properly maintaining a reference count somewhere or is corrupting memory and only indirectly causing the error. If most of your code is in labview, one thing to look out for is incorrectly specified calls to dlls from LabVIEW. If a call to a dll is incorrectly specified, either from LabVIEW or TestStand that can very easily lead to memory corruption and random errors later on in the code.
    I'd recommend trying to either debug and see where it's failing, if it's always failing in the same place. Or try to eliminate possibilities and reduce the called code to the minimum code required to reproduce the problem and then look for bugs in that code (paying special attention to the possibility of incorrectly specified dll calls and/or perhaps incorrectly maintained reference counts on COM objects).
    Another idea, to see if the problem is memory corruption caused by a vi, is to run all of your labview vis using the development environment (labview adapter setting), if so, any memory corruption would be in the labview process and not the main teststand process and should not bring down teststand.
    -Doug

  • Java and COM Object out parameters

    I have a COM object written in C++ that can't be modified. It has several methods with output parameters.
    Can java create an instance of the COM object and pass a reference to a Variant in this case or any objects to be filled by the COM object? My output parameter keeps coming back null, but I know that the COM object is working.
    Bill

    You didn't say anything about how you are bridging java <-> COM.
    If it's via JNI, one way you could deal with this is to write a "wrapper" dll that can speak COM, but which can turn the output data into something more palatable to java - say an object that the wrapper can return.

  • Type casting for properties accessed in COM Object

    I have a com object that I need to access which provides my a
    list of addresses in an Array. The object give me a property that
    has a count for the number of addresses and then I have a loop that
    calls the property which contains the address details to get each
    individual address each time passing to the property the INDEX
    value on the loop.
    This errors out each time.
    The error I get is
    Error casting an object of type to an incompatible type.
    This usually indicates a programming error in Java, although it
    could also mean you have tried to use a foreign object in a
    different way than it was designed.
    It appears the the variable type of the index is not
    compatible with the property of the component(which is an int).
    IS there some way to type cast the variable used as the index
    for CFLOOP to that of an INT?

    You can try to use the JavaCast("int", myValue) function. It
    works great for Java objects, but I'm not sure how well it will
    work for COM. Worth a try, I guess.
    In your case it would be something like:
    <cfobject type="COM" context="INPROC" action="create"
    name="MR" class="DLLNAME">
    <cfloop from="1" to="#AddressCount#" index="i">
    <cfset VDname = mr.vdsname(JavaCast("int", i))>
    <cfset VDaddress = mr.vdsaddress(JavaCast("int", i))#>
    <cfset VDXML = mr.VDSXML(JavaCast("int", i))>
    </cfloop>

  • Calling test sequence from CVI DLL that use ATL COM object does not work

    I am trying to call some DLL function writen in CVI from teststand. The CVI DLL is using ATL COM object(Written by me).
    The ATL COM object making instance of several ATL COM object inside it (including two controls that contains dialog). If I use a client writen in VC++ 6 and use the ATL COM (writen by me) works perfectly. But if I try to use it from CVI DLL it does not work any more.
    What is wrong? The client is passing an IUnknow interface to my component. Can anybody explain me what is wrong?

    It is not clear from your question as to what is specifically failing. If possible, one option would be to remove TestStand from the picture and see if the problem still occurs using a CVI EXE that invokes the CVI DLL.
    Scott Richardson - NI
    Scott Richardson
    National Instruments

  • How sharing a COM object with severeal test dlls in teststand

    I have several tests (dlls) accessing a DAQ board (not VI compliant) thanks to a COM object. I would like to keep one instance of this object, passing its reference to each test dll, instead of creating one in each test. How can I do that with TestStand?

    You can do one of two things to store a reference to the COM object in the context of TestStand so that you can pass it to successive steps in order for them to all use the same object instance.
    First, if you create the object in TestStand with an ActiveX Automation Adapter step, the method call to instantiate the object should return a reference to the object. If you designate an activex reference type local variable as the property to receive the reference during the creation operation, you should be able to pass this into methods that use IDispatch* parameters, or you can use the TestStand API to access the TestStand variable instead.
    The second scenario is very similar, in that if you don't create the object in TestStand but inside of a dll instea
    d, you can simply pass the parameter back from a function into a TestStand activex reference property variable or use the TestStand API inside of the dll to set the value of an activex reference property to the IDispatch of the object.
    To better understand how to use the ActiveX Automation Adapter and ActiveX Reference Variable Types, look at Chapter 13 of the TestStand User Manual under the section entitled "ActiveX Automation Adapter". I have also attached an example to this post that uses the ActiveX Automation Adapter and ActiveX reference datatype in a sequence that writes data to a Microsoft Excel spreadsheet and generates a chart from the data.
    Jason F.
    Applications Engineer
    National Instruments
    www.ni.com/ask
    Attachments:
    Write_Table_to_XL_and_Create_Chart.seq ‏53 KB

  • How to creat COM object from dll file?

    Hi,
    I tried to read about this topyc, but I didn't found eny example that creat
    COM object. I downloaded jacob.jar
    then I writed:
    ActiveXComponent ax = new ActiveXComponent("C:/MyJava/deploy/SMSCom.dll");
    Object SMSObj = ax.getObject();
    I get error (I put jacob.jar with all athers jars, I don't know way this erre)
    Exception occurred during event dispatching:
    java.lang.UnsatisfiedLinkError: no jacob in java.library.path
         at java.lang.ClassLoader.loadLibrary(Unknown Source)
         at java.lang.Runtime.loadLibrary0(Unknown Source)
         at java.lang.System.loadLibrary(Unknown Source)
         at com.jacob.com.Dispatch.<clinit>(Dispatch.java)file name: SMSCom.dll
    object name: SMSSender
    In VB this is the code:
    Object SMSObj = CreateObject("SMSCom.SMSSender");
    SMSObj.password = pass;
    SMSObj.Username = name;
    SMSObj.Source = phone;Thanks

    In Eclipse:
    1- To include jacob.jar for compile / run:
    Choose the Java perspective, then in the Package Explorer right-click on the project and choose Properties.
    Select Java Build Path from the left pane then the Librairies pane from the right.
    Click on Add External Jars button and select the jacob.jar file then click Open then Ok.
    2- To make jacob.dll and SMSCom.dll "visible" for run:
    Open your Debug (or Run) Java application configuration (the one for your project's main class).
    Select the Environment pane then click on Select button.
    Select Path and click on Ok button.
    Then re-select Path and click on Edit button.
    Add the two appropriate folders for jacob.dll and SMSCom.dll in the Path and click on Ok then Apply.
    Regards

  • How can I use a COM object that does not have a type library?

    Hello,
    I've created a com server in python for which I do not have a type library. I am able to call functions for this application in Python, TCL, I'm sure VB, etc. without the type library.
    Must I have a type library registered to use this COM object with Labview? I was hoping I could simply supply the name to the refnum (or the GUID) then call functions by passings strings to the invoke node. This does not seem to be possible - am I missing something?
    In the event that I cannot use a com server without a type library. Any recommendataions on how to create one? I'm wondering if I can use the same GUID and create a shell in LabWindows which generates the IDL/TBD file I need for Labview to see my
    com server.
    Any help is greatly appreciated.
    73,
    Timothy

    Timothy Toroni wrote:
    > Thanks for the info, however their example is labview server and
    > python client. I'm going the other way. It's good to know about
    > LabPython though...
    >
    > As of now, it seems to be there is no way to use a COM object without
    > a type library from inside LabView.
    Yes that is true. LabVIEW needs that to configure the Property and
    Methode Nodes correctly. Otherwise it would need to have a special
    Property and Method Node with a configuration dialog similar to the Call
    Library Node, but a LOT more complicated. Not sure many people could
    make use of that, and it would be a very tiring experience trying to get
    things setup in that way, by going through the edit, test, and crash
    cycle over and over again.
    Rolf Kalberm
    atter
    Rolf Kalbermatter
    CIT Engineering Netherlands
    a division of Test & Measurement Solutions

  • How can I call COM object in a servlet?

    Hi,
    Does oracle provide a bridge to call COM objects in a servlet? Is there any sample for doing this?
    Thanks,
    Archie

    Archi,
    Take a look at the following link:
    http://technet.oracle.com/products/ids/daily/jul12.html
    You can use J-Integra, one of JDeveloper's Extensions, in your Servlet to call any MS COM objects.

  • How to call a COM object from an Oracle Form?

    Hi All,
    Pls advice. How to call a COM object from an Oracle Form?
    Thanks.

    try asking the "Form" forum

  • Creating a COM object with CF9 32-bit on Windows Server 2008 R2 64-bit machine

    I'm using a 32-bit version of CF9 and it's installed on a Windows Server 2008 R2 machine (64-bit).  The problem I'm running into is that it won't allow me to create a COM object - it gives me the error, "no ntvinv in java.library.path null" when I try to run,
    <cftry>
    <cfobject type="COM" action="CONNECT" name="Engine" class="JRO.JetEngine">
    <cfcatch type="Any">
        <cfobject type="COM" action="CREATE" name="Engine" class="JRO.JetEngine">
    </cfcatch>
    </cftry>
    Then when I run it a 2nd time, I get "An exception occurred when instantiating a COM object. The cause of this exception was that: java.lang.RuntimeException: Can not use native code: Initialisation failed."
    Can you help me?

    Replying for your patchset installation pre-req error:
    Use below command:
    ./runInstaller -ignoreSysPrereqs
    Review MOS note 763143.1 for more info.

Maybe you are looking for

  • Changed Computer. Old HDD is now slave. FF is not finding old settings and saved passwords. Very Important Saved Passwords.

    Hi, I have changed my Computer. Essentially, the M/B, CPU, RAM, HDD, etc. I still have my old HDD and Mozilla was installed there. I have a lot of saved passwords on that Firefox. I have started Firefox from there itself. Yet, FF doesn't find those p

  • In java.lang.NumberFormatException

    Hello, my code can compile, but when I try to create an new TempEntry (String info), in java.lang.NumberFormatException keeps appearing by the time I get to my first integer. * Constructor for objects of class TempEntry public TempEntry(String info)

  • Error in doumentation?

    In the documentation on this page on step 3.1 when enabling Load Balancing for DA: https://technet.microsoft.com/en-us/library/jj134209.aspx there is an option to change the IPv6 Prefix. In the middle pane of the console, in the Step 2 DirectAccess S

  • Airport Express not working with cable modem

    I have an airport express that has been working perfectly.  I changed my internet provider and it suddently won't work -- no dns, no internet--even though other devices (including apple tv) are connecting with no problem.  [the cable modem (motorola)

  • GPIB Polling of an Instrument Register

    I have developed a VI using the event-driven producer-consumer template, and I am very happy with the performance. Now, I need to add another instrument to the system - a scope controlled over a GPIB interface. The scope control is easy and the drive