m4rc
m4rc

Reputation: 3006

No return value from C++ DLL using C#

Using a console application, I'm making use of a c++ com dll to call a function.

I have added the registered DLL as a reference for the project and then I am instantiating the object and calling the function. (I should note that I'm not using pinvoke as some other people seem to be)

I should be getting a string back as a result but I am just getting an empty string. The only way I can get any form of output is by enabling debugging for unmanaged code and from that I can see that it is executing correctly and returning a result.

I have had a search around stackoverflow and a few other sites and can't quite find anything that matches this. Any ideas what I'm doing wrong or how I can get it to return a value?

EDIT: As requested, here is the code -

COMMODCHECKLib.Modcheck mod = new COMMODCHECKLib.Modcheck();
string output = mod.check("123456");

Upvotes: 0

Views: 415

Answers (2)

m4rc
m4rc

Reputation: 3006

Well it seems that the documentation for the DLL was incorrect and gave the check function as the one I needed but infact there was a function called checkAllocate which is the one I needed to use. Apologies guys - many thanks for your time and efforts

Upvotes: 0

MartinStettner
MartinStettner

Reputation: 29164

I would suggest to first check, if the problem is within the C# code or the COM library. For that, you can use e.g. a VB-Script file (.vbs) like

(test.vbs)
Set mod = CreateObject("COMMODCHECKLib.ModCheck")
WScript.echo(mod.check("123456"))

Just run this script from the command line (entering test.vbs).

If this gives the desired output, you know at least, that the problem lies on the C# side.

Upvotes: 1

Related Questions