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. DllImport, function argument problems

DllImport, function argument problems

Scheduled Pinned Locked Moved C#
helptutorialcsharpalgorithmsdata-structures
1 Posts 1 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.
  • D Offline
    D Offline
    Daniel Monzert
    wrote on last edited by
    #1

    Hi there. I want to import a function of a simple C written DLL from within a C# project. Not that difficult... actually. But I keep getting exceptions. I spent hours for searching on the internet for articles that may help me but didn't find anything that helped me to solve my problem. This is the C code out of the header: [code]typedef struct tagHuffmanObj { int has_incomplete; int incomplete_node; char incomplete_byte; }HuffmanObj; void Compress(char *dest, const char *src, int *dest_size, int *src_size); void Decompress(char *dest, const char *src, int *dest_size, int *src_size, HuffmanObj *obj);[/code] Q1: What's the correct declaration for importing the functions? I tried different things on this, none of it worked. I keep getting NullReference exceptions but I don't know what exactly that means. Some time ago (1+ year) I read that NullReference expeptions come up upon passing wrong arguments to the function. The function in the dll is exactly compiled as given in the header, I recompiled the DLL since it's open source. public static extern void Compress(ref byte[] dest, ref byte[] source, ref int destSize, ref int srcSize); for example. I mean.. if C doesn't care about datatypes, the function would simlpy read the byte code given by dest/source with the given lengths. And I just pass it a byte array with the ascii codes. Q2: Is it correct, that the C# struct for HuffmanObj is just 2 int variables and a byte variable in the same order? Just to be sure.. I'm kinda confused on how to import the functions properly.

    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