LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

LabWindows/CVI DLL ATTACH and DETACH events

Hi All,

I would like to launch a function from inside my LabWindows/CVI DLL
when I load it.
I tried to place a simple function or pop message box in the case of the
ATTACH and DETACH events (see DLLMain construct below),
but my function and/or message box did not execute.

I'll appreciate your help,

Gil




int __stdcall DllMain (HINSTANCE hinstDLL, DWORD fdwReason, LPVOID
lpvReserved)
{
switch (fdwReason)
{
case DLL_PROCESS_ATTACH:
if (InitCVIRTE (hinstDLL, 0, 0) == 0)
return 0; /* out of memory */



break;
case DLL_PROCESS_DETACH:



CloseCVIRTE ();

break;
}

return 1;
}

int __stdcall DllEntryPoint (HINSTANCE hinstDLL, DWORD fdwReason, LPVOID
lpvReserved)
{
/* Included for compatibility with Borland */

return DllMain (hinstDLL, fdwReason, lpvReserved);
}
0 Kudos
Message 1 of 6
(3,790 Views)
Im not sure why this did not work for you

I tried the following and it worked

switch (fdwReason)
{
case DLL_PROCESS_ATTACH:
if (InitCVIRTE (hinstDLL, 0, 0) == 0)
return 0; /* out of memory */
else
MessagePopup("Test","test");
break;
case DLL_PROCESS_DETACH:
CloseCVIRTE ();
break;
}

But before you try to do anything complex in DLLmain, please check out this
link here for what you can and cannot do in Dllmain.

Hope this helps.
Bilal Durrani
NI
0 Kudos
Message 2 of 6
(3,783 Views)
Hi Bilal,
I did not 'break' any of the rule in the link you posted.
How did you load the DLL? Maybe it did not execute because I failed to load it properly.

Regards,

Gil
0 Kudos
Message 3 of 6
(3,777 Views)
You don't need a separate operation to load your DLL. From your calling application (an exe separate from your DLL) you just call one of your exported functions in your DLL. You don't directly call DllMain or DllEntryPoint.
Look at the sample programs that ship with CVI.
...\CVI\samples\dll\simple\cvi\readme.txt
...\CVI\samples\dll\simple\cvi\mydll.prj
...\CVI\samples\dll\simple\cvi\simple.prj
0 Kudos
Message 4 of 6
(3,771 Views)
Al S speaks true. When you have a Dllmain defined in your dll, the OS calls this function automatically when you load the dll. It does not matter if you load it using LoadLibrary() or if you have statically linked the import library. The OS is responsible for calling the appropriate ATTACH and detach events.

Any other function, you would need to call yourself.
Bilal Durrani
NI
0 Kudos
Message 5 of 6
(3,758 Views)
Hi Bilal and Al S,

I thank you for your answers, it helped me understand that using the attach mechanisem will not help me achieve my goal. I decided to explain what I am trying to do as a different topic (see link):

http://forums.ni.com/ni/board/message?board.id=180&message.id=14048

Thanks again,

Gil
0 Kudos
Message 6 of 6
(3,731 Views)