Discussion:
LoadLibary and Getprocaddress not working?!?
(too old to reply)
martinboecskoer
2008-08-08 15:10:07 UTC
Permalink
Hi,
 
i trie to im get a pointer to a dll function to pass it as a callback function pointer to another one. i wrote following dll in visual c++
 
code\

#include <windows.h>
HINSTANCE h = 0;
// die call library node konfigurerst du so:
// int32 myDLLload(const char* lib)
// lib ist ein Labview-String, den du als const char* übergibst!
extern "C" __declspec( dllexport) int myDLLload(LPCWSTR lib)
{
if(h == 0)
{
h = LoadLibrary(lib);
return 0; // ok
}
return 1; // error
}
// auch hier übergibst du füp proc einen LV-String als char*!
// addr übergibst du als pointer auf int32
extern "C" __declspec( dllexport) int myDLLgetprocaddr(const char* proc, int* addr, DWORD* err)
{
if(h != 0)
{
*addr = (int)GetProcAddress(h, proc);
return *addr == 0; // ok
}
*err = GetLastError();
return 1; // error
}
 
extern "C" __declspec( dllexport) void myDLLFree()
{
FreeLibrary(h);
h = 0;
}
/code
 
i passed the parameters for the loadlibary (lib) and getproc... (proc) as a c-string, but it doesnot work. i am not good in writing dlls at all (fortunately there are a lot of nice people in some forums that help a lot :) ) and i just dont know why that doesnot work.
anyone has a clue?
 
thanx
martin
Wiebe@CARYA
2008-08-11 09:28:43 UTC
Permalink
I'm not an expert, but I think you call the LoadLibrary with LPCWSTR, which
is an unicode string...

Why don't you call the dll's directly? It's much easier, since with an
external dll, you still need to do all the external calling. Also, it
already has been done:
http://forums.ni.com/ni/board/message?board.id=170&thread.id=39381&view=by_date_ascending&page=2 .
Although this does some more stuff, it also has a LoadLibrary and
GetProcAddress.

Regards,

Wiebe.
PaSB
2008-08-12 14:40:19 UTC
Permalink
Hi Martin, what exactly are you trying to accomplish? Calling a LabVIEW dll from VC++?<a href="http://zone.ni.com/devzone/cda/tut/p/id/2771" target="_blank">This website</a> explains a bit on adding the LabVIEW memory manager functionality. The best way would be to link against the labview.lib library file, as mentioned on the website. This library will provide the necessary methods for using all LabVIEW data types such as LStr, etc. There is <a href="http://digital.ni.com/manuals.nsf/webAdvsearch/8D930295FFBF9F7686256D2C00624728?OpenDocument&amp;vid=niwc&amp;node=132100_US" target="_blank">a manual</a> to be found here that explains the best approaches. Maybe you can explain in more detail what your goal is, so we can find the most efficient solution.Thanks and best regards,Peter
Loading...