Re: Sanity check on call to imported DLL function

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



On Wed, 10 Dec 2008 08:27:31 +0530, "G Himangi" <nospam@xxxxxxxxxx>
wrote in <#6OnNMnWJHA.5476@xxxxxxxxxxxxxxxxxxxx>:

Seems your struct declaration is wrong.

The IntPtr DataPID should not be present

That was commented out, so it is not being compiled. I should have
deleted it before posting. Sorry.

and the last char array should be defined similar to the way you
defined the DataPID array.

As a char array? I went back and rechecked the documentation and
found something that I had missed before. In the section entitled
"Default Marshaling for Strings", there is a subsection "Strings Used
in Structures" that indicates that it should be a System.String with
the attribute UnmanagedType.ByValTStr and the SizeConst attribute.
Here is the example given:

struct StringInfoT {
TCHAR * f1;
TCHAR f2[256];
};

[StructLayout(LayoutKind.Sequential, CharSet=CharSet.Auto)]
struct StringInfoT {
[MarshalAs(UnmanagedType.LPTStr)] public String f1;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst=256)] public String
f2;
}

However, I dont know if this is what is causing the changed member.

It would seem a little odd, given the sequential layout of the struct,
that the last member would affect the first. I'm going to give it a
shot nonetheless. If that doesn't work, I'll try the char array
instead and see what happens.
--
Charles Calvert | Web-site Design/Development
Celtic Wolf, Inc. | Software Design/Development
http://www.celticwolf.com/ | Data Conversion
(703) 580-0210 | Project Management
.



Relevant Pages