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
  1. Home
  2. General Programming
  3. C#
  4. DLL import and parameters

DLL import and parameters

Scheduled Pinned Locked Moved C#
csharpc++helptutorialquestion
2 Posts 2 Posters 0 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.
  • G Offline
    G Offline
    gmar
    wrote on last edited by
    #1

    ;)Hello, i'm using a dll with VC++ 6.0 i would like to use it with C#. My problem is that some type of data are not usable with c#. For exemple i can use char *xx as parameter , but when i want to use a pointer on a structure, it seems impossible to have it working. MyStruct { string field1; int field2; } [DllImport(@"C:\DLL\MyDll.dll",EntryPoint="myfunction",CharSet=CharSet.Ansi)] unsafe public static extern int myfunction(uint param1,short short param2, MyStruct *pointeronStruct); It is not working, [DllImport(@"C:\DLL\MyDll.dll",EntryPoint="ReadCard",CharSet=CharSet.Ansi)] unsafe public static extern int SecondFunction(uint param1,short param2, byte *field1, int *field2); so i need to split the structure, when there is only 2 fields, it's not a problem, but when you have 10 fields, it's not the same. As i cannot modify the dll, i decided to include this dll in a dll where is solve thoses kind of problem and then use the new dll with .NET. Does someone know how to solve this ? Thanks by advance

    J 1 Reply Last reply
    0
    • G gmar

      ;)Hello, i'm using a dll with VC++ 6.0 i would like to use it with C#. My problem is that some type of data are not usable with c#. For exemple i can use char *xx as parameter , but when i want to use a pointer on a structure, it seems impossible to have it working. MyStruct { string field1; int field2; } [DllImport(@"C:\DLL\MyDll.dll",EntryPoint="myfunction",CharSet=CharSet.Ansi)] unsafe public static extern int myfunction(uint param1,short short param2, MyStruct *pointeronStruct); It is not working, [DllImport(@"C:\DLL\MyDll.dll",EntryPoint="ReadCard",CharSet=CharSet.Ansi)] unsafe public static extern int SecondFunction(uint param1,short param2, byte *field1, int *field2); so i need to split the structure, when there is only 2 fields, it's not a problem, but when you have 10 fields, it's not the same. As i cannot modify the dll, i decided to include this dll in a dll where is solve thoses kind of problem and then use the new dll with .NET. Does someone know how to solve this ? Thanks by advance

      J Offline
      J Offline
      Jagadeesh VN
      wrote on last edited by
      #2

      I had a similar problem with a dll developed in Delphi, and using the same in VC++. First you will have to find out the equivalent data types in C# for all the parameters used in the dll. Most of the data types will be the same except for the structure. Declare a similar structure in C#, create an object of the same, and then pass the address of the object as a long value( which would get type casted automatically in the dll ). Hope this would solve your problem. :) "A robust program is resistant to errors -- it either works correctly, or it does not work at all; whereas a fault tolerant program must actually recover from errors."

      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