Unmanaged TYpes in API

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Howard Kaikow

    Unmanaged TYpes in API

    The FormatMessage API is specified as:

    DWORD FormatMessage(
    DWORD dwFlags,
    LPCVOID lpSource,
    DWORD dwMessageId,
    DWORD dwLanguageId,
    LPTSTR lpBuffer,
    DWORD nSize,
    va_list* Arguments)

    I am trying to convert this to C#. So far I've got:

    [System.Runtime. InteropServices .DllImport("ker nel32",
    EntryPoint="For matMessage", ExactSpelling=f alse,
    CharSet=System. Runtime.Interop Services.CharSe t.Ansi, SetLastError=tr ue)]
    private static extern uint FormatMessage (
    uint dwFlags,
    lpcvoid lpSource,
    uint dwMessageId, uint dwLanguageId,
    [MarshalAs(Unman agedType.LPTStr )]string lpBuffer,
    uint nSize,
    va_list* Arguments);

    Did I do LPTSTR correctly?
    What do I need to do for LPCVOID and va_list*?


  • Willy Denoyette [MVP]

    #2
    Re: Unmanaged TYpes in API


    "Howard Kaikow" <kaikow@standar ds.com> wrote in message
    news:Ob8sBtDaFH A.1384@TK2MSFTN GP09.phx.gbl...[color=blue]
    > The FormatMessage API is specified as:
    >
    > DWORD FormatMessage(
    > DWORD dwFlags,
    > LPCVOID lpSource,
    > DWORD dwMessageId,
    > DWORD dwLanguageId,
    > LPTSTR lpBuffer,
    > DWORD nSize,
    > va_list* Arguments)
    >
    > I am trying to convert this to C#. So far I've got:
    >
    > [System.Runtime. InteropServices .DllImport("ker nel32",
    > EntryPoint="For matMessage", ExactSpelling=f alse,
    > CharSet=System. Runtime.Interop Services.CharSe t.Ansi, SetLastError=tr ue)]
    > private static extern uint FormatMessage (
    > uint dwFlags,
    > lpcvoid lpSource,
    > uint dwMessageId, uint dwLanguageId,
    > [MarshalAs(Unman agedType.LPTStr )]string lpBuffer,
    > uint nSize,
    > va_list* Arguments);
    >
    > Did I do LPTSTR correctly?
    > What do I need to do for LPCVOID and va_list*?
    >
    >[/color]
    Try this...
    [DllImport("kern el32.dll", CharSet=CharSet .Auto, SetLastError=tr ue)]
    internal static extern int FormatMessage
    (int dwFlags,
    IntPtr lpSource,
    int dwMessageId,
    int dwLanguageId,
    StringBuilder lpBuffer,
    int nSize,
    IntPtr va_list_argumen ts);

    Willy.



    Comment

    • Howard Kaikow

      #3
      Re: Unmanaged TYpes in API

      Thanx, I'll give it a try.

      --
      http://www.standards.com/; See Howard Kaikow's web site.
      "Willy Denoyette [MVP]" <willy.denoyett e@telenet.be> wrote in message
      news:Ob4AeLFaFH A.2884@tk2msftn gp13.phx.gbl...[color=blue]
      >
      > "Howard Kaikow" <kaikow@standar ds.com> wrote in message
      > news:Ob8sBtDaFH A.1384@TK2MSFTN GP09.phx.gbl...[color=green]
      > > The FormatMessage API is specified as:
      > >
      > > DWORD FormatMessage(
      > > DWORD dwFlags,
      > > LPCVOID lpSource,
      > > DWORD dwMessageId,
      > > DWORD dwLanguageId,
      > > LPTSTR lpBuffer,
      > > DWORD nSize,
      > > va_list* Arguments)
      > >
      > > I am trying to convert this to C#. So far I've got:
      > >
      > > [System.Runtime. InteropServices .DllImport("ker nel32",
      > > EntryPoint="For matMessage", ExactSpelling=f alse,
      > > CharSet=System. Runtime.Interop Services.CharSe t.Ansi, SetLastError=tr ue)]
      > > private static extern uint FormatMessage (
      > > uint dwFlags,
      > > lpcvoid lpSource,
      > > uint dwMessageId, uint dwLanguageId,
      > > [MarshalAs(Unman agedType.LPTStr )]string lpBuffer,
      > > uint nSize,
      > > va_list* Arguments);
      > >
      > > Did I do LPTSTR correctly?
      > > What do I need to do for LPCVOID and va_list*?
      > >
      > >[/color]
      > Try this...
      > [DllImport("kern el32.dll", CharSet=CharSet .Auto, SetLastError=tr ue)]
      > internal static extern int FormatMessage
      > (int dwFlags,
      > IntPtr lpSource,
      > int dwMessageId,
      > int dwLanguageId,
      > StringBuilder lpBuffer,
      > int nSize,
      > IntPtr va_list_argumen ts);
      >
      > Willy.
      >
      >
      >[/color]


      Comment

      Working...