Code::Blocks Forums
User forums => Help => Topic started by: vcvycy on September 02, 2016, 06:07:46 am
-
/* Sorry For My Poor English =.=*/
The code below can run successfully in vs2012。
But when I compiled it in Codeblocks, Codeblocks always reported an error:
error: 'CreateProcessWithLogonW' was not declared in this scope|
It puzzled me~
#include<windows.h>
BOOL bCreateProc =CreateProcessWithLogonW (
wcUserName,
NULL,
wcPassword,
0,
NULL,
wcCommandLine,
NORMAL_PRIORITY_CLASS,
NULL,
NULL,
&si,
&pi
);
Then I maked a test:
use LoadLibray("Advapi32.dll") and GetProcName("CreateProcessWithLogonW")to call this api.
It Works!!!!!!!!!!!
So Why this happend?????
Code Like This:
HMODULE hDll=LoadLibrary("Advapi32.dll");
FARPROC p=GetProcAddress(hDll,"CreateProcessWithLogonW");
printf("%x\n",p);
BOOL WINAPI (*pfun)(
_In_ LPCWSTR lpUsername,
_In_opt_ LPCWSTR lpDomain,
_In_ LPCWSTR lpPassword,
_In_ DWORD dwLogonFlags,
_In_opt_ LPCWSTR lpApplicationName,
_Inout_opt_ LPWSTR lpCommandLine,
_In_ DWORD dwCreationFlags,
_In_opt_ LPVOID lpEnvironment,
_In_opt_ LPCWSTR lpCurrentDirectory,
_In_ LPSTARTUPINFOW lpStartupInfo,
_Out_ LPPROCESS_INFORMATION lpProcessInfo
);
pfun=(BOOL WINAPI (*)(
_In_ LPCWSTR lpUsername,
_In_opt_ LPCWSTR lpDomain,
_In_ LPCWSTR lpPassword,
_In_ DWORD dwLogonFlags,
_In_opt_ LPCWSTR lpApplicationName,
_Inout_opt_ LPWSTR lpCommandLine,
_In_ DWORD dwCreationFlags,
_In_opt_ LPVOID lpEnvironment,
_In_opt_ LPCWSTR lpCurrentDirectory,
_In_ LPSTARTUPINFOW lpStartupInfo,
_Out_ LPPROCESS_INFORMATION lpProcessInfo
))p;
STARTUPINFO si={sizeof(si)};
wchar_t name[100]=L"352871242@qq.com";
wchar_t pass[100]=L"pass";
wchar_t cmd[100] =L"notepad";
PROCESS_INFORMATION pi;
BOOL bCreateProc =(*pfun) (
name,
NULL,
pass,
0,
NULL,
cmd,
NORMAL_PRIORITY_CLASS,
NULL,
NULL,
(LPSTARTUPINFOW)&si,
&pi
);
-
https://msdn.microsoft.com/en-us/library/windows/desktop/ms682431(v=vs.85).aspx (https://msdn.microsoft.com/en-us/library/windows/desktop/ms682431(v=vs.85).aspx)
To compile an application that uses this function, define _WIN32_WINNT as 0x0500 or later.
AFAIK VS does it automatically, for CB use Project->Build Options->#defines
-
When I added "#define _WIN32_WINNT 0x0500" in "Build Options->Compiler settings->#defines",
It report
||=== Build: Debug in Test (compiler: GNU GCC Compiler) ===|
_WIN32_WINNT||No such file or directory|
0x0500||No such file or directory|
||=== Build failed: 2 error(s), 0 warning(s) (0 minute(s), 0 second(s)) ===|
When I added "#define _WIN32_WINNT 0x0500" in main.cpp file,I seems nothing hanppend,still reported that function CreateProcessWithLogonW was not declared in the scope.
Do I did something wrong?
-
When I added "#define _WIN32_WINNT 0x0500" in "Build Options->Compiler settings->#defines",
It report
||=== Build: Debug in Test (compiler: GNU GCC Compiler) ===|
_WIN32_WINNT||No such file or directory|
0x0500||No such file or directory|
||=== Build failed: 2 error(s), 0 warning(s) (0 minute(s), 0 second(s)) ===|
Yes, did it wrong.
From memory you need to add it like below; the CB defines are one per line.
When I added "#define _WIN32_WINNT 0x0500" in main.cpp file,I seems nothing hanppend,still reported that function CreateProcessWithLogonW was not declared in the scope.
Do I did something wrong?
You need to add the defines before any windows headers are included.
Edit: Fixed typos.
Tim S.
-
WOW!Problem Solved.
Just do as you say, Modify "#define _WIN32_WINNT 0x0500" to "_WIN32_WINNT=0x0500".
thanks!
When I want to use WinSock API ,I have to add "-lwsock32" in "Linker Settings",I perfer CB to VS because its convience.
But why there is so much constarin in windows development?