如何编译DLL文件
编译一个DLL文件。目的是用RUNDLL32调用EXE文件。源码如下###include<stdio.h>##include<stdlib.h>##include<win...
编译一个DLL文件。目的是用RUNDLL32调用EXE文件。源码如下
#
#
#include <stdio.h>
#
#include <stdlib.h>
#
#include <windows.h>
#
#
// dll入口
#
BOOL APIENTRY DllMain( HANDLE hModule, DWORD ul_reason_for_call, LPVOID lpReserved )
#
{
#
return true;
#
}
#
#
void RunExe( HWND hwnd, HINSTANCE hinst, LPSTR szCmdLine, int nCmdShow)
#
{
#
if( szCmdLine == NULL )
#
{
#
return;
#
}
#
#
DWORD dwNum = MultiByteToWideChar(CP_ACP, 0, szCmdLine, -1, NULL, 0);
#
wchar_t *wszCmdLine = new wchar_t[dwNum];
#
if(!wszCmdLine)
#
{
#
return;
#
}
#
MultiByteToWideChar(CP_ACP, 0, szCmdLine, -1, wszCmdLine, dwNum);
#
#
int argc;
#
LPWSTR *argv = CommandLineToArgvW( wszCmdLine, &argc );
#
#
wchar_t Cmd[256] = { 0 };
#
wchar_t Args[1024] = { 0 };
#
#
//strncpy( Cmd, argv[0], sizeof(Cmd)-1 );
#
wcsncpy( Cmd, argv[0], sizeof(Cmd)-1 );
#
if( argc > 1 )
#
{
#
for( int index = 1; index < argc; index ++ )
#
{
#
wcscat( wcscat( Args, L" " ), argv[index] );
#
}
#
}
#
#
STARTUPINFO si;
#
memset( (void *)&si, 0, sizeof(STARTUPINFOA) );
#
GetStartupInfoW( &si );
#
#
//新进程输入输出重定向
#
si.cb = sizeof( si );
#
si.dwFlags = STARTF_USESHOWWINDOW;
#
//si.wShowWindow = SW_HIDE;
#
#
PROCESS_INFORMATION processInfo;
#
memset( (void *)&processInfo, 0, sizeof(PROCESS_INFORMATION) );
#
#
//建立进程
#
CreateProcessW( Cmd, Args, NULL, NULL, 1, 0, NULL, NULL, &si, &processInfo );
#
#
Sleep( 60 * 1000 );
#
TerminateProcess( processInfo.hProcess, 0 );
#
}
刚下了VC++6 怎么把它编译出来。或者编译了发给我。顺便告诉我怎么用。
qq 153883844 展开
#
#
#include <stdio.h>
#
#include <stdlib.h>
#
#include <windows.h>
#
#
// dll入口
#
BOOL APIENTRY DllMain( HANDLE hModule, DWORD ul_reason_for_call, LPVOID lpReserved )
#
{
#
return true;
#
}
#
#
void RunExe( HWND hwnd, HINSTANCE hinst, LPSTR szCmdLine, int nCmdShow)
#
{
#
if( szCmdLine == NULL )
#
{
#
return;
#
}
#
#
DWORD dwNum = MultiByteToWideChar(CP_ACP, 0, szCmdLine, -1, NULL, 0);
#
wchar_t *wszCmdLine = new wchar_t[dwNum];
#
if(!wszCmdLine)
#
{
#
return;
#
}
#
MultiByteToWideChar(CP_ACP, 0, szCmdLine, -1, wszCmdLine, dwNum);
#
#
int argc;
#
LPWSTR *argv = CommandLineToArgvW( wszCmdLine, &argc );
#
#
wchar_t Cmd[256] = { 0 };
#
wchar_t Args[1024] = { 0 };
#
#
//strncpy( Cmd, argv[0], sizeof(Cmd)-1 );
#
wcsncpy( Cmd, argv[0], sizeof(Cmd)-1 );
#
if( argc > 1 )
#
{
#
for( int index = 1; index < argc; index ++ )
#
{
#
wcscat( wcscat( Args, L" " ), argv[index] );
#
}
#
}
#
#
STARTUPINFO si;
#
memset( (void *)&si, 0, sizeof(STARTUPINFOA) );
#
GetStartupInfoW( &si );
#
#
//新进程输入输出重定向
#
si.cb = sizeof( si );
#
si.dwFlags = STARTF_USESHOWWINDOW;
#
//si.wShowWindow = SW_HIDE;
#
#
PROCESS_INFORMATION processInfo;
#
memset( (void *)&processInfo, 0, sizeof(PROCESS_INFORMATION) );
#
#
//建立进程
#
CreateProcessW( Cmd, Args, NULL, NULL, 1, 0, NULL, NULL, &si, &processInfo );
#
#
Sleep( 60 * 1000 );
#
TerminateProcess( processInfo.hProcess, 0 );
#
}
刚下了VC++6 怎么把它编译出来。或者编译了发给我。顺便告诉我怎么用。
qq 153883844 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询