Calling a C++ function in a dll
1 posts in topic
Flat View  Flat View

Posted By:   Matthew_Brown
Posted On:   Thursday, November 1, 2001 01:54 PM

I'm creating a "wrapper" C++ class that will provide the interface between java and a DLL.
It will implement JNI and call a DLL. I need to load and calling a DLL.
I can load it, and the functions in the DLL are somewhat accessible(like I can call them without any arguements), but how do I pass parameters to the DLL functions?
The DLL code was written in Visual C++.

Re: Calling a C++ function in a dll

Posted By:   Abraham_Khalil  
Posted On:   Friday, November 30, 2001 11:33 PM

Here an example

ULONG getCPUSpeed() {
typedef FREQ_INFO (FAR *ClientCpuSpeed) (int);
ClientCpuSpeed lpfGetCpuSpeed;

long cpuSpeed = -1;

hLibrary = LoadLibrary("cpuinf32.dll");
if (hLibrary != NULL) {
lpfGetCpuSpeed = (ClientCpuSpeed) GetProcAddress(hLibrary, "cpuspeed");
cpuSpeed = lpfGetCpuSpeed(0).norm_freq;

FreeLibrary( hLibrary ) ;

return cpuSpeed;

In this example, I create a typedef as well on the next line to
assign it. Once I've got a pointer to a function, next load the dll.

lpfGetCpuSpeed = (ClientCpuSpeed) GetProcAddress(hLibrary, "cpuspeed");
calls a method cpuspeed in the dll

cpuSpeed = lpfGetCpuSpeed(0).norm_freq;
The passing of the arguments in this example is the zero
About | Sitemap | Contact