2005-5-6

     在应用程序中启动其他程序的方法:

1.    UINT WinExec(LPCSTR lpCmdLine,UINT uCmdShow)

Eg: if(WinExec(“cdplayer.exe”,SW_MAXIMIZE)<=31)

       AfxMessageBox(“运行CD播放器失败”);

Eg: WinExec("winmine.exe",SW_SHOWNORMAL);

WinExec("C://WINDOWS//System32//sol.exe",SW_SHOWNORMAL);

2.    STARTUPINFO  stinfo;

PROCESSINFO  procinfo;

CreateProcess(NULL,”calc.exe”,NULL,NULL,FALSE,NORMAL_PRIORITY_CLASS,NULL,NULL,& stinfo, & procinfo);

3.    ShellExecute(handle,”open”,”cdplayer.exe”,NULL,SW_SHOWNORMAL);

 Eg: 浏览C:/windows文件夹

        ShellExecute(handle,”explore”,”c:/windows”,NULL,NULL,SW_SHOWNORMAL);

     DLL中的导出函数的明确申明:

     __declspec(dllexport) int Fun(int x);

   应用程序中明确相应输入函数:

        __declspec(dllimport) int Fun(int x);

     DLL实例:

//DLL01.cpp(dll建立)

extern "C" _declspec(dllexport) void ShowMessage()

              {

                     AfxMessageBox("The function is in the MFC Dll");

              }

//调用

HMODULE hdll=::LoadLibrary(“D:/vc/DLL01/Debug/DLL01.dll”);//加载链接库

       if(hdll==NULL){

              MessageBox(“加载动态链接库失败”,"Warning",MB_OK|MB_ICONWARNING);

              return;}

       typedef void (*pShow)(); //类型、参数要符合dll函数

       pShow Show=(pShow)::GetProcAddress(hdll,"ShowMessage");

       if(Show==NULL)

MessageBox(“The function can’t be found!”,”Warning”,MB_OK|MB_ICONWARNING);

       else

              Show(); //调用加载动态链接库失败

 FreeLibrary(hdll);

     打开文件对话框选择文件路径

 CString filter,m_Path;

       filter="Dll(*.dll)|*.dll|All Files(*.*)|*.*||";

CFileDialog dlg(TRUE,".cpp","dll01.cpp",OFN_HIDEREADONLY,filter);

       if(dlg.DoModal()==IDOK)

              m_path=dlg.GetPathName();

       UpdateData(false);

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值