Passing structure from VC++ to C#
I'm using C# DLL in a VC++ application. I have some details in VC++ like
PageNumer
pageTitle
PageDesc
BoxDetail
I have to pass these to C# DLL. So I made one structure in VC++, then I pass that to C#. But I couldn't do that. Please help me.
VC++ Function:
struct SCS3OverVwPg
{
__int32 iOvrPgNo;
char sOvrPgTitle[30]; //OverView Page Title
};
void CToolTab::SendOverview()
{
SCS3OverVwPg *pOverVw = 0;
pOverVw = new SCS3OverVwPg;
Globals1::gwtoolbar->SetTree(pOverVw);
}
C# function:
public struct SCS3Over
{
Int32 iOvrPgNo;
char[] sOvrPgTitle;
}
pub开发者_StackOverflow中文版lic void SetTree(SCS3Over x)
{
MessageBox.Show("Data received");
}
If I do like this, it shows the error
error C2664: 'Tabcontrol::ToolBar::SetTree' : cannot convert parameter 1 from 'SCS3OverVwPg *' to 'SCS3Over'
If I change name in C# DLL to SCS3OverwPg
, it shows error of structure redifinition
. Please help me.
I will have to assume you are using managed C++...
Instead of redeclaring the struct in managed C++, just reference the struct type from the C# assembly, and use that when calling the function.
精彩评论