Re: DllImport into C#

From: Tim Mulholland (TimMulholland_at_nospamaddress.com)
Date: 02/12/04


Date: Thu, 12 Feb 2004 13:04:29 -0500

n/m, i found what the CallingConvention thing was. i declare mine with

__declspec(dllexport)

which one should i be using? They all seem to do the same thing (throw that
exception)

"Tim Mulholland" <TimMulholland@nospamaddress.com> wrote in message
news:%231tFQHZ8DHA.2472@TK2MSFTNGP10.phx.gbl...
> It was your post i was referring to, so thanks for responding.
> What do you mena you had to specify the calling convention in the
DllImport
> statement?
>
> I'm still very stumped about why i get an exception when i don't debug the
> unmanaged code, but no exception when i do...
>
> "Ted Sung" <teds@intex.com> wrote in message
> news:86dea8f5.0402120907.35005268@posting.google.com...
> > I was able to get something similar to work by using StringBuilder:
> >
> > .. FuncA( StringBuilder string ParamA ) ;
> >
> > It seems that the DllImport's default char set is ANSI so StringBuilder
> > marshals the parameter correctly. Also, my C function was declared
> > as CDECL and I had to specify the calling convention in the DllImport
> statement.
> >
> > Ted
> >
> >
> > "Tim Mulholland" <TimMulholland@nospamaddress.com> wrote in message
> news:<uBBLODM8DHA.3804@tk2msftngp13.phx.gbl>...
> > > just so you know, what i'm trying is
> > >
> > > [DllImport("MyDll.dll", EntryPoint="FuncA")]
> > > private static extern IntPtr FuncA([MarshalAs(UnmanagedType.LPStr)]
> string
> > > ParamA);
> > >
> > > as per something i saw a little bit below in the Interop NG.. but i'm
> > > getting a NullReferenceException when i make the calls to that
function
> and
> > > i'm wondering if its because of how i'm declaring it.
> > >
> > > "Tim Mulholland" <TimMulholland@nospamaddress.com> wrote in message
> > > news:%23K6vz5L8DHA.2540@TK2MSFTNGP11.phx.gbl...
> > > > Whats the correct C# datatype (or marshalling function or something)
> to
> > > use
> > > > when you're importing a function that has a signature similar to
> > > >
> > > > char* FuncA(char c[])
> > > >
> > > > ?
> > > >
> > > > Assuming you know that both the parameter for the function and the
> return
> > > > value are c-style strings?
> > > >
> > > > Thanks in advance!
> > > >
> > > > Tim
> > > >
> > > >
>
>



Relevant Pages

  • Re: DllImport into C#
    ... > I'm still very stumped about why i get an exception when i don't debug the ... >> It seems that the DllImport's default char set is ANSI so StringBuilder ... >> as CDECL and I had to specify the calling convention in the DllImport ...
    (microsoft.public.dotnet.framework.interop)
  • RE: .NET Runtime 2.0 Error - I need more details...
    ... so if you can not use this event to handle the exception. ... The default event logging behavior of console application is built into ... ConsoleException.Program.Main), calling mscorwks!JIT_Throw ... Microsoft Online Community Support ...
    (microsoft.public.dotnet.framework)
  • Re: Assertion on Type conversion
    ... The author states that "if a method has specified some pre-condition then the failure of that condition is the responsibility of the ... depends on the caller's ability to check for conditions, and assure them to be correct, prior to the calling of the method. ... An overlooked exception that could be handled gracefully. ... Implement a method like "IsValid" to do a runtime check first if your concerned about the ArgumentException being thrown. ...
    (microsoft.public.dotnet.languages.csharp)
  • RE: Microsoft.XLANGs.RuntimeTypes.InvalidPropertyTypeException
    ... Trying to access a data property on a message for which it has not ... Yes the exception is of significant concern; it is a major user error. ... Any exception thrown could delay the cleanup of resources, ... System.Text.StringBuilder.Append), calling mscorsvr!Ordinal76+0x1d925 ...
    (microsoft.public.biztalk.server)
  • Microsoft.XLANGs.RuntimeTypes.InvalidPropertyTypeException
    ... they still occur when we turn tracking off. ... Is this 'exception' of a significant concern? ... System.Text.StringBuilder.Append), calling mscorsvr!Ordinal76+0x1d925 ...
    (microsoft.public.biztalk.server)