Click here to Skip to main content
15,867,704 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi
I am working on a c++ application in visual studio 2015 and got a requirement to add a C# project to my application and call those C# functions from my c++ project.

But there is a case where one particular .net function is not getting called from my c++ project. After debugging i under stood that, that .net function has a call as follows:

public void DotNetFun()
{
Sample.Open();
}

The Sample is a class and Open is a static member function in .net project. This function is available from a third party dll. No source code available with us.

why this function (DotNetFun()) is not getting called? If i remove the statement Sample.Open() from that DotNetFun() then this function is getting called.

What I have tried:

IDecoderPtr pIDecode(__uuidof(CDecompresser));
pIDecode->DotNetFun((BSTR)lpzFileName, &vbIsValidFile,&lFileVersion);
Posted
Updated 12-Jun-19 23:29pm

 
Share this answer
 
The function does not match the signature you call it with: it is declared with no parameters, and you are passing three.

I'd check what you are trying to do a bit more closely first!

BTW: that isn't a .NET static function - it's an instance function.
 
Share this answer
 
v2
Comments
Sampath579 13-Jun-19 5:30am    
The code is just a sample i gave. If function signature does not match, my code wont get compile first.

IDecoderPtr pIDecode(__uuidof(CDecompresser));
pIDecode->DotNetFun();

Open is a static function in that third party dll. Sample is class in that dll.

The function which i am calling i.e., DotNetFun() is not a static function. Inside this function, there is a call as follows:

public void DotNetFun()
{
Sample.Open(); //open is a static function in third party dll.
}
OriginalGriff 13-Jun-19 5:37am    
So don't describe things as "static" when they aren't, - and don't give us code samples that are nothing like the actual code you are using. Didn't it occur to you that it's quite likely to be that actual parameters and what you are doing with them at one end or the other that is causing your problem? And that we can't even begin to help you unless we know what is *actually* going on?
Sampath579 13-Jun-19 6:05am    
In visual studio i have two projects (static libs).
1. C++ Project
2. .Net Dll

from my c++ project

#import "D:DotNet\\DecoderAndDecompresser.tlb" named_guids

void Test::Create()
{
IDecoderPtr pIDecode(__uuidof(CDecompresser));
pIDecode->DotNetFun();
}

In .net project

namespace DecoderAndDecompresser
{
public interface IDecoder
{
void DotNetFun();
};
public class CDecompresser : IDecoder
{
public void DotNetFun()
{
Sample.Open(); // Open is a static member function in one of the .netdll.
}
}
}


When i call DotNetFun() from my c++ code, control is not even going to that function and application getting terminated. If i remove that call i.e., Sample.Open() then there is no issues.

Hope it helps in understanding my sceniro.
Sampath579 1-Aug-22 0:07am    
Resolved the issue on my own after doing little more investigation.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900