calling a __stdcall function pointer in a c# application

  • Thread starter Thread starter varun_bwazz
  • Start date Start date
V

varun_bwazz

Guest
I have a c++ application(program.cpp ) and a .h file of c++ dll. I want to call the dll functions from a c# application . The problem is to use the function pointers in c#. Please help with this.

/*Program.h*/

#ifndef ess_cH
#define ess_cH

unsigned long long __stdcall ess_initialization(unsigned short serial);


unsigned char __stdcall ess_close(unsigned long long handle);


unsigned char __stdcall ess_get_serial(unsigned long long handle,
unsigned short * serial,
unsigned short * version);



/*Program.cpp*/

typedef unsigned long long(__stdcall *init)(int);
typedef int(__stdcall *serial)(unsigned long long, unsigned short *, unsigned short *);
typedef int(__stdcall *close)(unsigned long long);


int main(int argc, char *argv[])
{
/* Load DLL into memory */
HINSTANCE ProcDLL_ESS;

#ifdef _WIN64
ProcDLL_ESS = LoadLibrary(TEXT("ess_c_64.dll"));
#else
ProcDLL_ESS = LoadLibrary(TEXT("ess_c_32.dll"));
#endif

/* Declare pointers on dll functions */
init dll_init;
serial dll_serial;
close dll_close;

dll_init = (init)GetProcAddress(ProcDLL_ESS, "ess_initialization");
dll_serial = (serial)GetProcAddress(ProcDLL_ESS, "ess_get_serial");
dll_close = (close)GetProcAddress(ProcDLL_ESS, "ess_close");

unsigned long long essHandle = 0;
unsigned short Serial = 0;
unsigned short Version = 0;
unsigned char position = 0;

if (ProcDLL_ESS != NULL) {
std::cout << "ESS dll loaded" << std::endl;

/* Initialize device */
if (dll_init != NULL) {
/* Initialize the first SWITCHBOARD in Windows enumeration list */
essHandle = dll_init(0);
std::cout << "ESS session initialized" << std::endl;
}

/* Read device serial number */
if (dll_serial != NULL) {
/*Get the serial number of the SWITCHBOARD*/
dll_serial(essHandle, &Serial, &Version);
std::cout << "SWITCH BOARD SN: " << Serial << std::endl;
}

return EXIT_SUCCESS;

}

Continue reading...
 
Back
Top