Calling C/C++ dll functions from C# -


i trying call functions compiled c/c++ dll in c# program. have called several of functions having trouble couple.

compliled c/c++ function call:

decldir int ads1292r_get_version(unsigned char ads129x_version[]) { unsigned char wbuf[10]; unsigned char rbuf[10], retval =1; wbuf[0] = start_data_header;                // packet start header wbuf[1] = firmware_version_req;             // firmware version info command wbuf[2] = 0x00;                             // not used wbuf[3] = 0x00;                             // not used wbuf[4] = 0x00;                             // not used wbuf[5] = end_data_header;                  // packet end header wbuf[6] = '\n';   pcomport->write(wbuf, 7);                   // send command firmware sleep(5); memset(rbuf,0,7); pcomport->read(rbuf, 7);                    // receive response frimwate  if ((rbuf[0] == start_data_header)      && (rbuf[1] == firmware_version_packet)      && (rbuf[5] == end_data_header)) {     ads129x_version[0]= rbuf[2];            // major number     ads129x_version[1]= rbuf[3];            // minor number     retval = 0;                             // set return val su }  return retval; 

}

c# implementation (along wrapper function class):

  [dllimport("ads1292r_usb_lib.dll", entrypoint = "ads1292r_get_version")]     public static extern int ads1292r_get_version(byte[] x);      public int getversion()     {         byte[] datatemp = new byte[3];         int mydata = ads1292r_get_version(datatemp);         if (mydata == 0)         {             messagebox.show("1:" + datatemp[0].tostring()                              + " 2:" + datatemp[1].tostring()                              + " 3:" + datatemp[2].tostring());         }         return 0;     } 

at run-time, below error being raised. there missing?

updated error text:

"pinvokestackimbalance detected" "a call pinvoke function 'dlltalk!dlltalk.dllclass::ads1292r_get_version' has unbalanced stack. because managed pinvoke signature not match unmanaged target signature. check calling convention , parameters of pinvoke signature match target unmanaged signature."

don't forget callingconvention attribute setting well. also, denote if native c++ library trying invoke 64 or 32bit, can't load 32bit assemblies in 64bit process.

using 32bit or 64bit dll in c# dllimport


Comments

Popular posts from this blog

jquery - How can I dynamically add a browser tab? -

node.js - Getting the socket id,user id pair of a logged in user(s) -

keyboard - C++ GetAsyncKeyState alternative -