c# - Using unmanaged function in managed code giving error:Attempted to read or write protected memory -


i trying use c++ dll methods in c# project , 1 of method working fine other 1 giving error:attempted read or write protected memory. indication other memory corrupt. don't know reason behind it. enter image description here

enter image description here

pure guesswork of mine:

in c++ long different thing in c#. if c++ functions have parameters long or unsigned long, in c# should use int , uint respectively.

i guess issue, since using c#/long client port strange. don't need 64bit number that. if that's signature mismatch, third stirng parameter response damaged during marshalling , c++ side invalid pointer there.

your current c# implementation corresponds c++ signature:

long fk_sendresponse(string addr, long port, string response); //<-> int64 fk_sendresponse(char const* addr, int64 port, char* response) 

i guess wanted use:

/*c#*/ int fk_sendresponse(string addr, int port, string response); //<-> /*c++*/ long fk_sendresponse(char const* addr, long port, char* response) 

or

/*c#*/ uint fk_sendresponse(string addr, uint port, string response); //<-> /*c++*/ unsigned long fk_sendresponse(char* addr, unsigned long port, char* response) // (or, same speaking winapi types) /*c++*/ hresult fk_sendresponse(lpstr addr, dword port, lpstr response) 

Comments

Popular posts from this blog

Android : Making Listview full screen -

javascript - Parse JSON from the body of the POST -

javascript - Chrome Extension: Interacting with iframe embedded within popup -