LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

GetExternalModuleAddr return error -5

I use LoadExternalModule function to open a static library(.lib), then use GetExternalModuleAddr to get the address of a function in the .lib, but the GetExternalModuleAddr report an error, -5, Undefined reference, sometimes, It works well. Can anyone help me to solve the problem?
0 Kudos
Message 1 of 5
(3,852 Views)
Hi jasonxia,

Are you able to call this static library from other environments (i.e. C++)?

Are you getting a valid ID of the loaded module (i.e. the return value)? The LoadExternalModule function obtains the address of an identifier in the module.  Its is important to remember that the identifier must be either a variable or function name defined globablly in the external module.  In the LoadExternalModule help, there is a small code snippet located above the Parameters section that demonstrates how to correctly use this function. Have you looked at that snippet? 

What do you mean it works sometimes? Could you please elaborate on that?

The help topics for both functions are very good so I would make sure you have reviewed them.

Best Regards,
Jonathan N.
National Instruments
0 Kudos
Message 2 of 5
(3,823 Views)
Hi Jonathan N,
 
Thank you for your reply.
 
I haven't tried calling this static library from other environment. I am sure the ID of the loaded module is valid.

Sometimes I can't get the address of a function, I disable the source codes of the function, then input a new one with the same name, then I can get it's address.
 
I also encountered a case, if I input the OutputDebugString function after GetExternalModuleAddr, I can get the address of a function in static library, but if I take out OutputDebugString, I can't get it.
 
Sometimes originally I can get the address of a function, but afer I edit some codes, build the static library, I can't get it.
 
Now I think it is likely that the source codes or the editor of CVI itself causes the problem, I feel erratic, so I now edit the source codes with other editor, then compile with the compiler of CVI.

Best Regards,
Jasonxia
0 Kudos
Message 3 of 5
(3,807 Views)
Hi jasonxia,

What do you mean "disable the source codes"? Are you going back into your library source, commenting out the function you can't call, creating a new function with the same name, then rebuilding the library? At that point, are you saying that the application that uses the library can't find that function?

When you say "OutputDebugString" function, are you talking abotu DebugPrintf or some function you created? With that function, when you use the function, you can get the address of the function in the library and when you don't use that function, you can't?

Can you provide some simple example that I can test to validate and observe this behavior? What you are describing really doesn't make a lot of sense to me.

Thanks

Best Regards,
Jonathan N.
National Instruments
0 Kudos
Message 4 of 5
(3,798 Views)
Hi jasonxia,

One of my co-workers brought up a good point that I forgot about. You can use the GetExternalModuleAddrEx function to obtain a list of undefined symbols if the function fails because there are undefined symbols.

Now one assumption is that calling OutputDebugString is loading up some SDK library in which you don't have linked into your application. When you don't call OutputDebugString, the library that you need (or something that you are calling needs) isn't loaded.  The OutputDebugString function is located in the Kernel32.dll file. One test would be to add the Kernel32.lib import library to your CVI project and see if you can call your function without making a call to OutputDebugString.  You can find our SDK version of Kernel32.lib in the <CVI>\sdk\lib\msvc directory.

Best Regards,
Jonathan N.
National Instruments
0 Kudos
Message 5 of 5
(3,795 Views)