Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C#
  4. how to wrap some dll functions from VC6

how to wrap some dll functions from VC6

Scheduled Pinned Locked Moved C#
csharptutorialquestion
4 Posts 2 Posters 1 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • Y Offline
    Y Offline
    yyf
    wrote on last edited by
    #1

    Hi, everyone I am using a dll developped in VC6. There are some functions I don't know how to wrap it in C#. 1. one function's parameter use self defined type, type definition is like this: #ifndef LPLONG typedef long far *LPLONG; /* 32 bit */ #endif 2. one function's parameter use 'BOOL *' 3. one function's parameter use 'char *' 4. one function's return value use 'char *' 5. one function's parameter use a structure 6. one function's parameter use a structure * How shall I deal with these? Thanks in advance.

    H 1 Reply Last reply
    0
    • Y yyf

      Hi, everyone I am using a dll developped in VC6. There are some functions I don't know how to wrap it in C#. 1. one function's parameter use self defined type, type definition is like this: #ifndef LPLONG typedef long far *LPLONG; /* 32 bit */ #endif 2. one function's parameter use 'BOOL *' 3. one function's parameter use 'char *' 4. one function's return value use 'char *' 5. one function's parameter use a structure 6. one function's parameter use a structure * How shall I deal with these? Thanks in advance.

      H Offline
      H Offline
      Heath Stewart
      wrote on last edited by
      #2

      1. ref int 2. ref bool 3. [MarshalAs(UnmanagedType.LPStr)]string 4. [return: MarshalAs(UnmanagedType.LPStr)]string 5. Just pass the struct, but see the docs for the StructLayoutAttribute 6. ref _YourStruct_ All these - escept for 3 and 4 - are value types so you use ref or out (the latter if you don't need to pass any initial value to your functions). Don't use ref or out with a string because it is already a reference type. Both char* and char[] are strings since a string is only an array of characters. Since you're using char and not wchar_t (or TCHAR), you must marshal them as ANSI strings.

      Microsoft MVP, Visual C# My Articles

      Y 1 Reply Last reply
      0
      • H Heath Stewart

        1. ref int 2. ref bool 3. [MarshalAs(UnmanagedType.LPStr)]string 4. [return: MarshalAs(UnmanagedType.LPStr)]string 5. Just pass the struct, but see the docs for the StructLayoutAttribute 6. ref _YourStruct_ All these - escept for 3 and 4 - are value types so you use ref or out (the latter if you don't need to pass any initial value to your functions). Don't use ref or out with a string because it is already a reference type. Both char* and char[] are strings since a string is only an array of characters. Since you're using char and not wchar_t (or TCHAR), you must marshal them as ANSI strings.

        Microsoft MVP, Visual C# My Articles

        Y Offline
        Y Offline
        yyf
        wrote on last edited by
        #3

        How about void *? Thanks.

        H 1 Reply Last reply
        0
        • Y yyf

          How about void *? Thanks.

          H Offline
          H Offline
          Heath Stewart
          wrote on last edited by
          #4

          IntPtr

          Microsoft MVP, Visual C# My Articles

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups