M
Maloney
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(dllexport) 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(LayoutKind.Sequential)]
public struct SStatus
{
public long fileLength;
public long filePosition;
}
public class VitoSoundExplorer
{
[DllImport("TestDll.dll", EntryPoint="GetStatus")]
public static extern bool GetStatus(ref SStatus status);
public bool GetStatus()
{
SStatus st= new SStatus();
GetStatus(ref st);
return true;
}
}
}
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(dllexport) 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(LayoutKind.Sequential)]
public struct SStatus
{
public long fileLength;
public long filePosition;
}
public class VitoSoundExplorer
{
[DllImport("TestDll.dll", EntryPoint="GetStatus")]
public static extern bool GetStatus(ref SStatus status);
public bool GetStatus()
{
SStatus st= new SStatus();
GetStatus(ref st);
return true;
}
}
}