1 /* win32dll.c - make the newlisp.exe usable as a DLL
3 Copyright (C) 2008 Lutz Mueller
5 This program is free software: you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation, either version 3 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
23 /* note that DLL compile with MinGW is still in development */
25 #define EXPORT __declspec(dllexport) __stdcall
26 #define DLLCALL EXPORT
31 extern void loadStartup(char *name
);
32 extern LPSTR
getLibname(void);
33 extern int evalSilent
;
35 extern SYMBOL
* mainArgsSymbol
;
38 int dllInitialized
= 0;
41 char libName
[MAX_LINE
] = "newlisp.dll";
43 void initializeMain(void)
45 char name
[MAX_LINE
+ 1];
47 WSAStartup(MAKEWORD(1,1), &WSAData
);
57 mainArgsSymbol
->contents
= (UINT
)getCell(CELL_EXPRESSION
);
60 GetModuleFileName(GetModuleHandle(libName
), name
, MAX_LINE
);
68 /* ------------ initialize DLL (gets called by Windows) ----------------- */
70 extern STREAM errorStream
;
74 int CALLBACK
LibMain(HANDLE hModule
, WORD wDataSeg
, WORD cbHeapSize
, LPSTR lpszCmdLine
)
80 /* called automatically from nl-import when DLL is loaded from newLISP */
82 int DLLCALL
dllName(LPSTR name
)
84 strncpy(libName
, name
, MAX_LINE
);
89 /* ---- imported and called from a client using newlisp.dll ---- */
91 LPSTR DLLCALL
newlispEvalStr(LPSTR cmd
)
93 if(!dllInitialized
) initializeMain();
101 executeSymbol(errorEvent
, NULL
);
102 return((LPSTR
)libStrStream
.buffer
);
105 return((LPSTR
)errorStream
.buffer
);
108 openStrStream(&libStrStream
, MAX_STRING
, 1);
109 executeCommandLine(cmd
, (UINT
)&libStrStream
, NULL
);
111 if(evalSilent
) evalSilent
= 0;
113 return((LPSTR
)libStrStream
.buffer
);
117 LPSTR DLLCALL
dllEvalStr(LPSTR cmd
)
119 return(newlispEvalStr(cmd
));
124 /* ------------ called from Windows when unloading DLL ------------------ */
126 int DLLCALL
WEP (int bSystemExit
)