Signal Generators

cancel
Showing results for 
Search instead for 
Did you mean: 

ShellExecute bug with niFgen

I have a problem with niFgen version 2.4.0.49153.

If I call niFgen_init() or niFgen_InitWithOptions(), then I cannot call ShellExecute successfully!

Lets say I call

ShellExecute(NULL, "open", "http://www.google.com", NULL, NULL, SW_SHOWNORMAL);

I get the error message SE_ERR_ACCESSDENIED.

If however I never call
niFgen_init(), then the ShellExecute call is completed successfully...

Does anyone know how to fix this issue?
0 Kudos
Message 1 of 5
(7,610 Views)

Calling CoInitialize(NULL) before the call to niFgen_init()  will solve the problem.

The issue is caused by the fact that the niFgen uses the IVI Configuration Server C API which is a C wrapper over a COM component. By default, the C API initializes COM for every thread in MTA (apartment) mode. It appears that ShellExecute attempts to initialize COM in STA mode (which will fail) but it does not check to see if the thread has already been initialized with a different threading model and take appropriate action. We will report this bug to Microsoft.

Best regards.

Message 2 of 5
(7,577 Views)
ElGrimo,

It turns out that the encountered behavior is not really a bug - if it was one, it could be from the point to view of inadequate documentation, but  once you hear the issue details you just might agree with me that it's not the most easily documentable thing until you come across it.

From what I was able to see with the debugger and Windows symbols, it appears that the ShellExecute() implementation goes through a COM mechanism resulting in an invokation of a CoInitialize() looking-like function. Additionally, NI-Fgen driver is an IVI driver and through the IVI Engine uses the IVI Configuration Store - a COM component - through its C API. From what my colleagues in the IVI group tell me, it appears that these two COM components have different threading models which can cause one not to load if the other one loads first. To illustrate in more details what is going on with resepct to invocation of CoInitialize(), please see this posting.

There is a work-around in this case. Your application could call CoInitialize(NULL) for each thread (if there are more than one) before calling any of the NI-Fgen functions. This will initialize the threads in the appropriate mode that would work both for the shell and the IVI components.

Regards,
Regrads,
Sead Suskic
National Instruments
Message 3 of 5
(7,570 Views)
By the way, I apologize for the spelling errors - I hit the _submit post_ button a little sooner that I intended. At this moment there is not much _senior software engineer_ about me.
Regrads,
Sead Suskic
National Instruments
0 Kudos
Message 4 of 5
(7,563 Views)
Thanks everyone for the solution and technical details!

I am now calling CoInitialize before initializing the signal generator, and everything is fine.



0 Kudos
Message 5 of 5
(7,555 Views)