如何在VC编写的Dll中调用其它可执行文件(*.exe)?

Anth 2000-07-14 11:11:00
诸位专家,大家好:
最近因工作需要编写一动态链接库来实现ODBC操作,即将本地机上的数据文件导入远程(Oracle)数据库服务器上,因为考虑到用 VC 实现对Oracle多个表的非绑定读写有一定的困难,故想通过VB来实现这一部分操作,但如何在程序中控制却不知道,VB中倒是有一Shell函数,不知VC中如何实现,诸位VC高手如有这方面的经验,恳请指教,多谢!!!
E_Mail: Anthonycha@cmmail.com
Tel : 021-62196860 or 62955700 or 64021174(home)
Name : 查(zha)国平
...全文
209 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
sean 2000-07-14
  • 打赏
  • 举报
回复
例子:
To explore a folder, use the following call:
ShellExecute(handle, "explore", path_to_folder, NULL, NULL, SW_SHOWNORMAL);

sean 2000-07-14
  • 打赏
  • 举报
回复
handle 用NULL代替行不行?
Anth 2000-07-14
  • 打赏
  • 举报
回复
Mr sean的方案我曾尝试过,但ShellExecute函数的第一个参数(HWND hWnd)如何在动态链接库中确定?
To explore a folder, use the following call:
ShellExecute(handle, "explore", path_to_folder, NULL, NULL, SW_SHOWNORMAL);

Anth 2000-07-14
  • 打赏
  • 举报
回复
用CreateProcess是可以的,我已测试过,但当我用一个VC程序调用这个DLL时,却发生了错误,不知为何?我的dll函数代码如下:
extern "C" _declspec(dllexport) int myExec()
{
STARTUPINFO StartupInfo;
PROCESS_INFORMATION ProcessInfo;
memset(&StartupInfo,0,sizeof(StartupInfo));
StartupInfo.cb=sizeof(StartupInfo);
CreateProcess ("e:\\aa.exe",NULL,NULL,NULL,FALSE,0,NULL,NULL,&StartupInfo,&ProcessInfo);
return 1;
}


调用时的代码如下:
typedef int (SQRTPROC)();
HINSTANCE hInstance;
SQRTPROC *pFunction;
VERIFY(hInstance=::LoadLibrary("d:\\Anthony\\anth_prj\\vcprj\\NewDll\\debug\\NewDll.dll"));
VERIFY(pFunction=(SQRTPROC *)::GetProcAddress(hInstance,"myExec"));
int rr=(*pFunction)(); //Call dll function
sean 2000-07-14
  • 打赏
  • 举报
回复
The CreateProcess function creates a new process and its primary thread. The new process executes the specified executable file.

BOOL CreateProcess(
LPCTSTR lpApplicationName,
// pointer to name of executable module
LPTSTR lpCommandLine, // pointer to command line string
LPSECURITY_ATTRIBUTES lpProcessAttributes, // process security attributes
LPSECURITY_ATTRIBUTES lpThreadAttributes, // thread security attributes
BOOL bInheritHandles, // handle inheritance flag
DWORD dwCreationFlags, // creation flags
LPVOID lpEnvironment, // pointer to new environment block
LPCTSTR lpCurrentDirectory, // pointer to current directory name
LPSTARTUPINFO lpStartupInfo, // pointer to STARTUPINFO
LPPROCESS_INFORMATION lpProcessInformation // pointer to PROCESS_INFORMATION
);

sean 2000-07-14
  • 打赏
  • 举报
回复
看看下面这个行不行?
WinExec
The WinExec function runs the specified application.

This function is provided for compatibility with 16-bit Windows. Win32-based applications should use the CreateProcess function.

UINT WinExec(
LPCSTR lpCmdLine, // address of command line
UINT uCmdShow // window style for new application
);

PatrickGamp 2000-07-14
  • 打赏
  • 举报
回复
用CreateProcess或CreateProcessAsUser

16,472

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC相关问题讨论
社区管理员
  • 基础类社区
  • Web++
  • encoderlee
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

        VC/MFC社区版块或许是CSDN最“古老”的版块了,记忆之中,与CSDN的年龄几乎差不多。随着时间的推移,MFC技术渐渐的偏离了开发主流,若干年之后的今天,当我们面对着微软的这个经典之笔,内心充满着敬意,那些曾经的记忆,可以说代表着二十年前曾经的辉煌……
        向经典致敬,或许是老一代程序员内心里面难以释怀的感受。互联网大行其道的今天,我们期待着MFC技术能够恢复其曾经的辉煌,或许这个期待会永远成为一种“梦想”,或许一切皆有可能……
        我们希望这个版块可以很好的适配Web时代,期待更好的互联网技术能够使得MFC技术框架得以重现活力,……

试试用AI创作助手写篇文章吧