Click here to Skip to main content
16,004,927 members
Home / Discussions / C#
   

C#

 
GeneralProblem deleting file after loading in imagelist.. Pin
abcxyz824-Apr-05 8:02
abcxyz824-Apr-05 8:02 
GeneralRe: Problem deleting file after loading in imagelist.. Pin
_eulogy_4-Apr-05 13:27
_eulogy_4-Apr-05 13:27 
GeneralNewbie help: ListView with Dropdown column Pin
b_p_smith4-Apr-05 7:54
b_p_smith4-Apr-05 7:54 
GeneralRe: Newbie help: ListView with Dropdown column Pin
Luis Alonso Ramos4-Apr-05 15:03
Luis Alonso Ramos4-Apr-05 15:03 
GeneralRe: Newbie help: ListView with Dropdown column Pin
b_p_smith4-Apr-05 15:39
b_p_smith4-Apr-05 15:39 
GeneralRe: Newbie help: ListView with Dropdown column Pin
mav.northwind4-Apr-05 20:08
mav.northwind4-Apr-05 20:08 
GeneralRe: Newbie help: ListView with Dropdown column Pin
b_p_smith5-Apr-05 1:49
b_p_smith5-Apr-05 1:49 
GeneralMarshalling MyStruct[] from C# to C++ API Pin
Grimolfr4-Apr-05 7:25
Grimolfr4-Apr-05 7:25 
I have an API I'm wrapping in C#, and I'm having trouble tweaking the DllImport.

Here's the struct definition in C#:
[
MarshalAs(
	UnmanagedType.Struct,
	SizeConst = 512,
	CharSet = CharSet.Ansi
	)
]
public struct MyStruct
{
	[MarshalAs(UnmanagedType.I4)]public Int32 Size;
	[MarshalAs(UnmanagedType.LPStr, SizeConst = 508)]public String Name;
}


In C:
public struct MyStruct
{
	int size,
	char[508] name
}


And the C function declaration:
EXPORT void ListFiles(void* buffer, DWORD count)
{
     //Populate the buffer with /count/ records
}


The idea is to pass in a pointer to a buffer. The API function will fill that buffer with count records. Each record being byte data in the format of MyStruct.

I can successfully retrieve the data by passing in a buffer of type byte[512 * count]. But then I have to manually parse the data with BitConverter calls in a for loop.

What I'm trying to do is declare an array of MyStruct[count], and set up a DllImport that will properly marshal that array into the API, so that the API can fill the structures directly, with no need for me to parse data on return.

I've had no success with this whatsoever using MarshalAs(UnmanagedType.LPArray) or trying to let the compiler do automatic marshalling. Everything I've tried results in an array of structures that all have size 0 and null names.

Anyone have any pointers or suggestions to help me figure out how to marshal an array of structs from C# as a void* in C++?


Grim
(aka Toby)
MCDBA, MCSD, MCP+SB


SELECT * FROM users WHERE clue IS NOT NULL
GO
(0 row(s) affected)

GeneralRe: Marshalling MyStruct[] from C# to C++ API Pin
Daniel Turini4-Apr-05 8:24
Daniel Turini4-Apr-05 8:24 
Generalreferencing a control on another form Pin
kornstyle4-Apr-05 7:08
kornstyle4-Apr-05 7:08 
GeneralRe: referencing a control on another form Pin
tdciDoug4-Apr-05 7:36
tdciDoug4-Apr-05 7:36 
GeneralRe: referencing a control on another form Pin
Luis Alonso Ramos4-Apr-05 7:53
Luis Alonso Ramos4-Apr-05 7:53 
GeneralRe: referencing a control on another form Pin
kornstyle4-Apr-05 8:26
kornstyle4-Apr-05 8:26 
QuestionWrite a format provider ?? Pin
Ray-v4-Apr-05 5:59
Ray-v4-Apr-05 5:59 
AnswerRe: Write a format provider ?? Pin
Luis Alonso Ramos4-Apr-05 15:07
Luis Alonso Ramos4-Apr-05 15:07 
GeneralWindow State Pin
Finn Grimwood4-Apr-05 5:51
Finn Grimwood4-Apr-05 5:51 
GeneralRe: Window State Pin
Tom Larsen4-Apr-05 10:29
Tom Larsen4-Apr-05 10:29 
GeneralRe: Window State Pin
Finn Grimwood6-Apr-05 2:48
Finn Grimwood6-Apr-05 2:48 
GeneralCustom control Property error..... Pin
chettu4-Apr-05 5:00
chettu4-Apr-05 5:00 
QuestionCase insensitive string replace WITHOUT regex? Pin
mav.northwind4-Apr-05 4:46
mav.northwind4-Apr-05 4:46 
General[C# / ASP.net] Reading / Moving objects within Listbox Pin
Jaymz6664-Apr-05 3:38
Jaymz6664-Apr-05 3:38 
GeneralRe: [C# / ASP.net] Reading / Moving objects within Listbox Pin
Judah Gabriel Himango4-Apr-05 4:33
sponsorJudah Gabriel Himango4-Apr-05 4:33 
QuestionHow to get audio level from the microphone Pin
maberk4-Apr-05 3:36
maberk4-Apr-05 3:36 
GeneralProgram Interruption From External Messagebox Pin
Black Dhalia4-Apr-05 3:06
Black Dhalia4-Apr-05 3:06 
GeneralDouble Click Pin
Simon Wren4-Apr-05 3:00
professionalSimon Wren4-Apr-05 3:00 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.