Here's my DLL source (testsub.cpp, created as Project | New Workspace | Library | Dynamic Library):
Code: Select all
extern "C"
{ __declspec(dllexport) int addit( int a, int b ); }
int addit (int a, int b) { return a+b;}
Code: Select all
#include <stdio.h>
[DllImport("testsub.dll")]
public static extern 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;
}
1) I think I've got the two projects building in sequence with the Build | Batch Build... window, is that the right way to build both items - the console app and the dll?
2) When I build everything, the debug area has only the testsub.o object, and no testsub.dll file. It has the dependency files for both main and testsub. And I can't find the main.o anywhere, nor main.exe. How do I get the .dll and .exe file out of the compiles? And to run it, do I put the .dll and .exe on the same area and just run the .exe in a DOS window?
3) How do I pass strings back and forth to a DLL? Is the address space of main in the same context as the dll so I can just pass a pointer back and forth (argument and return value)? Or...?
4) General question about dll stuff - it seems I have to name both sources .cpp, I can't name them .c even if they're otherwise just vanilla C sources, is that correct?