Problem in Calling C ++ DLL from C # code

Source: Internet
Author: User
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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.