Re: Sanity check on call to imported DLL function



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

  • Re: how to handle a class objects data set?
    ... In the C language, a "struct" is like a VB UDT. ... strings can vary in size from zero to many ... > Is there a way to address a class object's data set consisting of UDT ...
    (microsoft.public.vb.winapi)
  • Re: structs for data transfer?
    ... > John Harrison wrote: ... >> Write some code to convert the struct you want to send into a char array. ... or sentinels and delimeters for the ends of strings. ...
    (comp.lang.cpp)
  • Re: A C Adventure: your comments are welcome
    ... are unified by being in a struct. ... Any part of the tree is represented by any node ... void pointers raise their pretty little heads. ... and multi-byte strings so you don't have to use wchar ...
    (comp.lang.c)
  • A C Adventure: your comments are welcome
    ... WE DEVELOP STRINGS AS A STRUCT ... note that there's no point in a"void"ing void pointers in C ... because C makes it easy to change pointer type. ...
    (comp.lang.c)
  • Re: Byte oriented data types in python
    ... So how do you compute the struct format for that? ... strings in the struct module in a reasonable way, ... strings of 8-bit bytes. ...
    (comp.lang.python)

Loading