2

I am using reactivision library which is written in C. I am trying to make it a dll file so that my c# program can call the functions. I browse a lot of threads and none of them is about converting so many files to one dll. In the c source file, some type definition looks like:

typedef struct PartialSegmentTopology{ struct Region black_leaf_regions_head; struct Region black_leaf_container_regions_head; struct Region root_regions_head; }PartialSegmentTopology;

I don't know where to insert '__declspec(dllexport)'.

Another issue is if I also need to insert it to the implementation(i.e. .c file)? My guess is I only need to do this in the header file. Please correct me if I am wrong.

Any help is appreciated.

Update: I followed this link to generate my dll file. But when I call the function in my c# code, it thrown DllNotFoundException though I put this dll file in correct folder.(I tried both bin/Debug and the project folder.)

Nemojjw
  • 21
  • 4
  • You don't have to add `__declspec` to the code, just use a `.def` file and the linker to generate the `.dll` and import library from the original `.lib` file. – Captain Obvlious Jul 03 '15 at 18:52
  • Do you mean writing one .def file and exporting all the functions in this file? – Nemojjw Jul 03 '15 at 19:13
  • Yes, you export all necessary functions via the `.def` file. – Captain Obvlious Jul 03 '15 at 19:24
  • You can't (and don't have to) export `typedef`s and `struct`s – wimh Jul 03 '15 at 19:45
  • Maybe [this](http://stackoverflow.com/questions/30581837/linker-error-when-calling-a-c-function-from-c-code-in-different-vs2010-project/30583411#30583411) can help with organizing your project. As for the `DllNotFoundException` a possible cause and resolution can be found [here](http://stackoverflow.com/questions/1246486/dllnotfoundexception-but-dll-is-there) – CristiFati Jul 03 '15 at 21:15

0 Answers0