Using unmanaged dll in c#: how to marshal a struct

Tech-Archive recommends: Fix windows errors by optimizing your registry

From: Thomas183 (gogglwoggl_at_gmx-dot-de.no-spam.invalid)
Date: 03/18/04


Date: 18 Mar 2004 16:51:14 -0600

Hi,

I have a unmanaged c++ dll, and want to call a function
"dlltest(mystruct a)"of it.
The Parameter mystruct is a struct which consists of a array of
strings:

struct mystruct
{
char * myArray[100];
}

I searched the net for on hole day, to find a way to marshal this.
I have tried the following in C#:

[ StructLayout (LayoutKind.Sequential, CharSet = CharSet.Ansi)]
public struct x_struct
{
[MarshalAs(UnmanagedType.LPArray, SizeConst=2)]

public [] string d;
};

[DllImport ("MyFile.dll", callingConvention.StdCall)]]
public static extern string dlltest(x_struct X);

The dll is in the system32 dir and functions with other structs (only
int) worked fine.

But with this one i get a EntryPointNotFound exception.

Thanks for your help

Thomas
mailto: gogglwoggl@gmx.de

 Posted Via Usenet.com Premium Usenet Newsgroup Services
----------------------------------------------------------
    ** SPEED ** RETENTION ** COMPLETION ** ANONYMITY **
----------------------------------------------------------
                http://www.usenet.com



Relevant Pages

  • Re: Marshaling char *... HELP, PLEASE!
    ... As soon as you need the C DLL to modify the string passed, you cannot use default string marshaling - StringBuilders are not supported in structs. ... code to only one struct with one char *, but when i try to call the ... "Cannot marshal field 'str' of type 'memmap': ...
    (microsoft.public.dotnet.framework.interop)
  • Re: Problem in performance of calling a dialog in DLL(Windows prog
    ... The 'buff' struct is not required at DLL interface, ... I rewrote the 'buff' struct storing an array of CString's inside, ... you make your life easier using robust container and string ...
    (microsoft.public.vc.mfc)
  • Re: passing struct from vb to c dll
    ... I am having some problem for getting values in struct from the c dll. ... Declare Function GetMemberInfo Lib "xyz" (pInfo As MBRINFO) As Long ... MBRINFO.szMember is a fixed length string 80 characters. ...
    (comp.lang.basic.visual.misc)
  • Re: Problem in performance of calling a dialog in DLL(Windows programm
    ... The 'buff' struct is not required at DLL interface, so I moved it away from public DLL header and put it in private DLL implementation file ... you make your life easier using robust container and string classes instead of TCHAR* raw pointers. ...
    (microsoft.public.vc.mfc)
  • Re: Accessing Memory Mapped File Help !!!!!!!
    ... I look through the DLL source code and find the following ... permissions for other apps to at a minimum read the mmf, ... createfileformapping I get the following error: ... struct LocalTraceBufferPointers is a structure used by the tracing ...
    (microsoft.public.windowsce.embedded)