Question : Errors Compiling DLL

hey all
i am trying to compile the following DLL in visual studio but i am getting these errors

Error      13      fatal error LNK1120: 2 unresolved externals      C:\Documents and Settings\HElamin\My Documents\Visual Studio
2008\Projects\SpawnProcess\Debug\SpawnProcess.dll

Error      11      error LNK2019: unresolved external symbol __imp__RpcRevertToSelf@0 referenced in function _SpawnProcessInNTDesktop      SpawnProcess.obj

Error      12      error LNK2019: unresolved external symbol __imp__RpcImpersonateClient@4 referenced in function _SpawnProcessInNTDesktop      SpawnProcess.obj
Code Snippet:
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
// SpawnProcess.cpp : Defines the entry point for the DLL application.
//
//#include "stdafx.h"
#include 
#include 
#include 
#include 
#include 
BOOL APIENTRY DllMain( HANDLE hModule,
DWORD ul_reason_for_call,
LPVOID lpReserved
)
{
return TRUE;
}
BOOL APIENTRY SpawnProcessInNTDesktop(LPSTR exeName,LPSTR parameters,LPSTR 
currDirectory)
{
DWORD dwThreadId;
HWINSTA hwinstaSave;
HDESK hdeskSave;
HWINSTA hwinstaUser;
HDESK hdeskUser;
RPC_BINDING_HANDLE h = NULL;
char buffer[256];
char desktopName[80];
STARTUPINFO startInfo;
PROCESS_INFORMATION processInfo;
// Ensure connection to service window station and desktop, and
// save their handles.
hwinstaSave = GetProcessWindowStation();
dwThreadId = GetCurrentThreadId();
hdeskSave = GetThreadDesktop(dwThreadId);
// Impersonate the client and connect to the User's
// window station and desktop.
RpcImpersonateClient(h);
hwinstaUser = OpenWindowStation("WinSta0", TRUE, MAXIMUM_ALLOWED);
if (hwinstaUser == NULL)
{
RpcRevertToSelf();
return 0;
}
SetProcessWindowStation(hwinstaUser);
hdeskUser = OpenDesktop("Default", 0, TRUE, MAXIMUM_ALLOWED);
RpcRevertToSelf();
if (hdeskUser == NULL)
{
SetProcessWindowStation(hwinstaSave);
CloseWindowStation(hwinstaUser);
return 0;
}
SetThreadDesktop(hdeskUser);
//Use CreateProcess to spawn process
//
lstrcpy(desktopName,"WinSta0\\Default");
memset(&startInfo,0,sizeof startInfo);
startInfo.cb = sizeof startInfo;
startInfo.lpDesktop = desktopName;
wsprintf(buffer,"%s %s",exeName, parameters);
if(!CreateProcess(NULL,
buffer,
NULL,
NULL,
TRUE,
CREATE_NO_WINDOW|CREATE_DEFAULT_ERROR_MODE|NORMAL_PRIORITY_CLASS,
NULL,
currDirectory,
&startInfo,
&processInfo))
{
LPVOID lpMsgBuf;
FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER |
FORMAT_MESSAGE_FROM_SYSTEM |
FORMAT_MESSAGE_IGNORE_INSERTS,
NULL,
GetLastError(),
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language
(LPTSTR) &lpMsgBuf,
0,
NULL );
LocalFree( lpMsgBuf );
return 0;
}
//
SetThreadDesktop(hdeskSave);
SetProcessWindowStation(hwinstaSave);
CloseDesktop(hdeskUser);
CloseWindowStation(hwinstaUser);
return TRUE;
}

Answer : Errors Compiling DLL

ok, first one is clear, a debug build can only run when debug DLLs are installed on the target machine (so usually when VS is installed).

About the second I don't know, but it might be the 'CREATE_NO_WINDOW' flag in 'CreateProcess' might be a problem. Try to do the same without this flag ...
Random Solutions  
 
programming4us programming4us