I've spent several days looking for info about precisely how to do DLLs and have found bits and pieces here and there but noplace that ties it all together. I'm thinking this could grow into a 'how-to' for DLLs which might be useful for others as well. I'd like to have code in there that people could actually use.
At the moment, I'm primarily interested in C# calling into C, but it'd be good to have one place that describes any-to-any types. Also, having a static link example would be good too. I'm using codelite.org v4684 for compiling.
In fact, it might be worth discussing this off-line so that the discussion (and my mistakes) don't add too much noise to the forum, and then I can just post the result when it's done.
So here are my examples:
DLL "C" code:
extern "C"
{ __declspec(dllexport) int addit( int a, int b ); }
int addit (int a, int b) { return a+b;}
Main "C" code (which doesn't compile so I obviously have the syntax wrong):
#include <stdio.h>
extern __declspec(dllimport)int addit( int a, int b );
int main(int argc, char **argv)
{
int x=2; int y=3;
int answer = addit(x,y);
printf("hello world, answer is %d\n", answer);
return 0;
}
I would like to have examples for C++/C, C#/C, C/C as well as dynamically linked (.dll) and statically linked at build time, as well as VB if somebody would like to provide that, I'd be willing to create an html 'how-to'.
Oh, and also how to have string-type args and return value.
TIA!