如何在c ++中返回两个不同的变量? [英] How to return two different variable in c++?
问题描述
$ $ $ $ $ $ $ $ $ $ $ $ $
{
return x;
}
}
在C#
[DllImport(example.dll,CallingConvention = CallingConvention.Cdecl)]
public static extern int mainfun();
我只知道如何从C ++返回并调用一个变量到C#。我正在编写一个程序,我需要从C ++ dll
( like return x,y;)中调用C#中的两个不同的变量。请求我需要帮助。
EDIT1:
在C ++中
struct Point
{
int count_err;
int语句;
} obj
externC
{
__declspec(dllexport)Point mainfun()
{
return obj;
}
}
在C#
[StructLayout(LayoutKind.Sequential)]
public struct Point
{
public int errsize;
public int statmnt;
}
[DllImport(example.dll,CallingConvention = CallingConvention.Cdecl)]
public static extern Point mainfun();
errsize = mainfun();
statmnt = mainFun();
这里errsize发出错误 - errsize在当前上下文中不存在 .. 该怎么办?
EDIT2:
在C#中
total_errors.Text = p.errsize.ToString();
给出相同的错误 - 当前的名称p不存在。上下文
定义新的数据结构或数组,这样:
C ++:
struct Point
{
int count_err;
int语句;
} obj;
externC
{
__declspec(dllexport)Point mainfun()
{
return obj;
}
}
C#:
[StructLayout(LayoutKind.Sequential)]
public struct Point
{
public int errsize;
public int statmnt;
}
[DllImport(example.dll,CallingConvention = CallingConvention.Cdecl)]
public static extern Point mainfun();
Point p = mainfun();
var errsize = p.errsize;
var statmnt = p.statmnt;
dll C++
extern "C"
{
__declspec(dllexport) int mainfun()
{
return x;
}
}
In C#
[DllImport("example.dll", CallingConvention = CallingConvention.Cdecl)]
public static extern int mainfun();
I only know how to return and call one variable from C++ to C#. I am writing a program where i need to call two different varables in C# from c++ dll (like return x,y;). Please i need help.
EDIT1:
In C++
struct Point
{
int count_err;
int statement;
} obj;
extern "C"
{
__declspec(dllexport) Point mainfun()
{
return obj;
}
}
In C#
[StructLayout(LayoutKind.Sequential)]
public struct Point
{
public int errsize;
public int statmnt;
}
[DllImport("example.dll", CallingConvention = CallingConvention.Cdecl)]
public static extern Point mainfun();
errsize = mainfun();
statmnt = mainfun();
Here errsize is giving an error-"the name 'errsize' does not exist in the current context".. What to do?
EDIT2:
In C#
total_errors.Text = p.errsize.ToString();
giving same error-"the name 'p' does not exist in the current." context"
Define new struct or array of data. Something like this:
C++:
struct Point
{
int count_err;
int statement;
} obj;
extern "C"
{
__declspec(dllexport) Point mainfun()
{
return obj;
}
}
C#:
[StructLayout(LayoutKind.Sequential)]
public struct Point
{
public int errsize;
public int statmnt;
}
[DllImport("example.dll", CallingConvention = CallingConvention.Cdecl)]
public static extern Point mainfun();
Point p = mainfun();
var errsize = p.errsize;
var statmnt = p.statmnt;
这篇关于如何在c ++中返回两个不同的变量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!