From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Run a function defined in a DLL, Using CVI. DLL created using VC?

I am trying to call a function that is defined in a DLL. This DLL is created in VC++ Ver 6.0 as a Win32 Dynamically Linked Library. I have a set of routines that are called by this function within the DLL. I am exporting the function using the __cdecl specifier for it to be called in LabWindows CVI.

In CVI I use the following routine to load the DLL

ModuleID = LoadExternalModuleEx("F:\\SelfTest\\Debug\\SelfTest.lib",__CVIUserHInst);

This function is successful. Next I try to get a pointer to the function using the routine

mAddress = GetExternalModuleAddr (ModuleID, "DoSelfTest(1,0,0,0)", &mStatus);

Here I get an error saying that the module has not been defined globally in the DLL. (Return Cod
e -10). I request you to kindly help me out of this problem. Also kindly let me know how I shud run the fucntion DoSelfTest(int,int,int,int) after getting a pointer to that function.

Also, Is it possible to create a DLL in MFC with dialog resources and call this DLL from within CVI so that my CVI application displays the dialogs created in MFC. Please Let me know.

Thanking You

Yours Sincerely
Sampath P. Kumaran
Engineer, MEL Systems And Services Ltd.
Chennai India.
0 Kudos
Message 1 of 4
(2,924 Views)
Did you mean LoadExternalModuleEx("SelfTest.dll",__CVIUserHInst) ?

I assume that your prototype has the DLL export during definition of the DLL.C file. I always forgot the part in my DLL's functions.

__declspec(dllexport) __cdecl DoSelftest( int, int, int, int );

When I encountered a problem like yours, I always tested the VC DLL itself to verify that the function was truly exported.
- I did this by going to Windows NT4 Explorer (does not exist in my new Win2K machine), right-click on DLL file, and QuickView. This used to display the exported functions, and all imported functions it needed.
0 Kudos
Message 2 of 4
(2,924 Views)
I often call functions in VC++ 6.0 DLL's from CVI. I typically don't need pointers to functions so I don't LoadExternalModule and GetExternalModuleAddr. I do the following.
1. Add the DLL .lib file to the CVI project.
2. Include the DLL .h file defining the functions to be called.
3. Call the DLL function directly from CVI.
There's some more discussion here.
0 Kudos
Message 3 of 4
(2,924 Views)
You can also use dependency walker to see if the function was truly exported.

Suppose if you've defined your function in this manner,

void funcy(int, int)

GetExternalModuleAddress would return a pointer to the function to you. So your function pointer should be defined like

void (*myfuncypointer)(int,int);

once myfuncypointer gets a value, you can just invoke it like a normal function

myfuncypointer(int, int)

Check out the fp help for GetExternalModuleAddr for more info.

Hope this helps

Bilal Durrani
NI
Bilal Durrani
NI
0 Kudos
Message 4 of 4
(2,924 Views)