I'm trying to pass a structer from C# to a C dll in .Net Compact Framework
This partially works. If in the GetStatus I only set -- status->fileLength
= 10; -- and not the second variable then filelength = 10 and fileposition =
0, but if i set the second one only or both of them then they are fileLength
= 47244640266 and filePosition = 0; Like the memory is getting over wrote.
What is the correct way of passing a structure by reference on the Compact
Framework.
here is my code
In the C dll
-------------------------------------------
----------------in the header
struct FileStatus
{
long fileLength;
long filePosition;
};
extern "C" __declspec(dlle xport) bool GetStatus (FileStatus* status);
----------------
---------------in the cpp
bool GetStatus (FileStatus* status)
{
status->fileLength = 10;
status->filePosition = 11;
return true;
}
--------------------------------------------
int my C# code i have
--------------------------------------------
namespace Controls
{
[StructLayout(La youtKind.Sequen tial)]
public struct SStatus
{
public long fileLength;
public long filePosition;
}
public class VitoSoundExplor er
{
[DllImport("Test Dll.dll", EntryPoint="Get Status")]
public static extern bool GetStatus(ref SStatus status);
public bool GetStatus()
{
SStatus st= new SStatus();
GetStatus(ref st);
return true;
}
}
}
------------------------------------------
Any Ideas
thanks
This partially works. If in the GetStatus I only set -- status->fileLength
= 10; -- and not the second variable then filelength = 10 and fileposition =
0, but if i set the second one only or both of them then they are fileLength
= 47244640266 and filePosition = 0; Like the memory is getting over wrote.
What is the correct way of passing a structure by reference on the Compact
Framework.
here is my code
In the C dll
-------------------------------------------
----------------in the header
struct FileStatus
{
long fileLength;
long filePosition;
};
extern "C" __declspec(dlle xport) bool GetStatus (FileStatus* status);
----------------
---------------in the cpp
bool GetStatus (FileStatus* status)
{
status->fileLength = 10;
status->filePosition = 11;
return true;
}
--------------------------------------------
int my C# code i have
--------------------------------------------
namespace Controls
{
[StructLayout(La youtKind.Sequen tial)]
public struct SStatus
{
public long fileLength;
public long filePosition;
}
public class VitoSoundExplor er
{
[DllImport("Test Dll.dll", EntryPoint="Get Status")]
public static extern bool GetStatus(ref SStatus status);
public bool GetStatus()
{
SStatus st= new SStatus();
GetStatus(ref st);
return true;
}
}
}
------------------------------------------
Any Ideas
thanks
Comment