Hi!
I am calling a C ++ DLL function from my C # code. But facing the problem in a function called inside that C ++ function.
That's how I'm referring to the C ++ DLL function inside my C # class: code:
Class testinterop {[Dllimport ("dbapi. DLL ", entrypoint =" deleterecfromdb ", exactspelling = false, setlasterror = true, charset = charset. unicode)] internal extern static intdeleterecfromdb ([financialas (unmanagedtype. lpwstr)] stringempname, [financialas (unmanagedtype. lpwstr)] string deptname );Public testinterop () {} static void main (string [] ARGs ){Testinterop. deleterecfromdb ("KT", "Dep-01 ");}}
now my c ++ function is written in dbapi. cpp as: Code:
dbapireturns deleterecfromdb (cstring empid, cstring depname) {try {int returns; // check for required fieldif ( checkrequiredfield (EMPI D) = false ) return missingrequiredfield; If (checkrequiredfield (depname) = false) return missingrequiredfield; pserverinterface-> deleterec (combcstr (empid ), ccombstr (depname), & returns); If (returns! = 1) Return (SUCCESS); else return (failure);} catch (_ com_error & CE) {return comerror;} catch (...) {return unknownerror ;}}
When I call this function, I get 'unknownerror' on the function checkrequiredfield (). If I bypass this function the code works fine. checkrequiredfield () is define as following: code:
Checkrequiredfield (cstring field) {If (field. getlength () <= 0) return false; return true ;}
I suspect that there must be some problem in the way I'm doing the parameter allocation alling.
Please help.
Thanks and regards
KT.