linker error
lodo
lodovico at giaretart.net
Tue Jul 10 10:51:33 PDT 2012
Let suppose I'm writing a library for Win32 applications called
"mylibrary".
The code of a program, called "UserProgram", that uses this
library would be like this:
UserProgram.d:
import mylibrary;
import std.c.windows.windows;
int WinMain(HINSTANCE hInst,HINSTANCE hPrevInst,LPSTR cmdLine,int
cmdShow)
{
//initialization of mylibrary
//user code
//de-initialization of mylibrary
}
What i was trying to do with prova0 and prova00 was calling
WinMain inside mylibrary, doing initialization and then call a
user-defined procedure with only the user-code. Then, doing
de-initialization and returning from WinMain inside the libary.
In this way, the user have to define only his code. Something
like this:
mylibrary.d:
public import std.c.windows.windows;
extern(C) UserMain();
int WinMain(HINSTANCE hInst,HINSTANCE hPrevInst,LPSTR cmdLine,int
cmdShow)
{
//initialization of mylibrary
UserMain();
//de-initialization of mylibrary
}
UserProgram.d:
import mylibrary;
extern(C) void UserMain()
{
//user code
}
I think this second way is much cleaner for the user and prevent
him from using mylibrary without correct initialization and
de-initialization.
I can't use static module initializers for this task because i
need the parameters of WinMain for the initialization.
P.S.: Sorry for my english, I know I'm not very good in it.
More information about the Digitalmars-d-learn
mailing list