温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

详解MFC/C++调用易语言的整数型和文本型与VS2010互动

发布时间:2020-09-06 22:57:55 来源:脚本之家 阅读:321 作者:laozhang 栏目:编程语言

1、LoadDll.cpp

#include "StdAfx.h"
#include "LoadDLL.h"

pMFCdll_OneVOID_OneVOID    MFCdll_OneVOID_OneVOID;
pMFCdll_OneWORD_OneVOID    MFCdll_OneWORD_OneVOID;
pMFCdll_OneCHAR_OneVOID    MFCdll_OneCHAR_OneVOID;


pMFCdll_OneWORD_OneWORD    MFCdll_OneWORD_OneWORD;
pMFCdll_OneWORD_TwoWORD    MFCdll_OneWORD_TwoWORD;
pMFCdll_OneWORD_ThreeWORD  MFCdll_OneWORD_ThreeWORD;
pMFCdll_OneWORD_FourWORD  MFCdll_OneWORD_FourWORD;
pMFCdll_OneWORD_FiveWORD  MFCdll_OneWORD_FiveWORD;
pMFCdll_OneWORD_SixWORD    MFCdll_OneWORD_SixWORD;


pMFCdll_OneWORD_OneChar    MFCdll_OneWORD_OneChar;
pMFCdll_OneWORD_TwoChar    MFCdll_OneWORD_TwoChar;
pMFCdll_OneWORD_ThreeChar  MFCdll_OneWORD_ThreeChar;
pMFCdll_OneWORD_FourChar  MFCdll_OneWORD_FourChar;
pMFCdll_OneWORD_FiveChar  MFCdll_OneWORD_FiveChar;
pMFCdll_OneWORD_SixChar    MFCdll_OneWORD_SixChar;


pMFCdll_OneChar_OneChar    MFCdll_OneChar_OneChar;
pMFCdll_OneChar_TwoChar    MFCdll_OneChar_TwoChar;
pMFCdll_OneChar_ThreeChar  MFCdll_OneChar_ThreeChar;
pMFCdll_OneChar_FourChar  MFCdll_OneChar_FourChar;
pMFCdll_OneChar_FiveChar  MFCdll_OneChar_FiveChar;
pMFCdll_OneChar_SixChar    MFCdll_OneChar_SixChar;


pMFCdll_OneChar_OneWORD    MFCdll_OneChar_OneWORD;
pMFCdll_OneChar_TwoWORD    MFCdll_OneChar_TwoWORD;
pMFCdll_OneChar_ThreeWORD  MFCdll_OneChar_ThreeWORD;
pMFCdll_OneChar_FourWORD  MFCdll_OneChar_FourWORD;
pMFCdll_OneChar_FiveWORD  MFCdll_OneChar_FiveWORD;
pMFCdll_OneChar_SixWORD    MFCdll_OneChar_SixWORD;


HINSTANCE  g_Hinstance;  //实例句柄


//加载DLL
BOOL LoadDll(char *name)
{
  
  if(g_Hinstance != NULL) return TRUE;  //如果g_Hinstance不为空就返回

  MFCdll_OneWORD_SixWORD = NULL;  //这里是加载ZJY_SoftOverTime用的
  MFCdll_OneCHAR_OneVOID = NULL;  //这里是加载ZJY_GetSystemDisk用的

  g_Hinstance = LoadLibrary(name);
  if(g_Hinstance == NULL)
  {
//    AfxMessageBox("加载dll动态库失败!");
    return FALSE;
  }

  MFCdll_OneWORD_SixWORD = (pMFCdll_OneWORD_SixWORD)GetProcAddress(g_Hinstance, "ZJY_SoftOverTime");
  MFCdll_OneCHAR_OneVOID = (pMFCdll_OneCHAR_OneVOID)GetProcAddress(g_Hinstance, "ZJY_GetSystemDisk");
  if(NULL == MFCdll_OneWORD_SixWORD || NULL == MFCdll_OneCHAR_OneVOID)
  {
//    AfxMessageBox("加载动态库MFCCallBackDllTest函数失败");
    FreeLibrary(g_Hinstance);
    g_Hinstance = NULL;
    return FALSE;
  }
  return TRUE;
}

//卸载DLL
void UninstallDll()
{
  if (g_Hinstance != NULL)
  {
    MFCdll_OneWORD_SixWORD = NULL;
    MFCdll_OneCHAR_OneVOID = NULL;
    FreeLibrary(g_Hinstance);
    g_Hinstance = NULL;
  }
}

2、LoadDll.h

#ifndef __MFCCLOADDLL_H
#define __MFCCLOADDLL_H

#include <windows.h>

BOOL LoadDll(char *name);  //加载DLL
void UninstallDll();    //卸载DLL

/************************************************************************/
/*易语言:没参数带返回值的,不带的。
/***********************************************************************/
typedef void  (WINAPI *pMFCdll_OneVOID_OneVOID)  ();  //返回VOID
typedef WORD  (WINAPI *pMFCdll_OneWORD_OneVOID)  ();  //返回WORD
typedef char * (WINAPI *pMFCdll_OneCHAR_OneVOID)  ();  //返回CHAR

/************************************************************************/
/*易语言:整数型接口  <返回值,整数型>(整数型 a, 整数型 b,整数型 c,整数型 d,整数型 e,整数型 f)*/
/***********************************************************************/
typedef WORD (WINAPI *pMFCdll_OneWORD_OneWORD)  (WORD a);  //返回WORD
typedef WORD (WINAPI *pMFCdll_OneWORD_TwoWORD)  (WORD a , WORD b);  //返回WORD
typedef WORD (WINAPI *pMFCdll_OneWORD_ThreeWORD)(WORD a , WORD b ,WORD c);  //返回WORD
typedef WORD (WINAPI *pMFCdll_OneWORD_FourWORD)  (WORD a , WORD b ,WORD c ,WORD d);  //返回WORD
typedef WORD (WINAPI *pMFCdll_OneWORD_FiveWORD)  (WORD a , WORD b ,WORD c ,WORD d ,WORD e);  //返回WORD
typedef WORD (WINAPI *pMFCdll_OneWORD_SixWORD)  (WORD a , WORD b ,WORD c ,WORD d ,WORD e,WORD f);  //返回WORD

typedef WORD (WINAPI *pMFCdll_OneWORD_OneChar)  (char * a);  //返回WORD
typedef WORD (WINAPI *pMFCdll_OneWORD_TwoChar)  (char * a , char * b);  //返回WORD
typedef WORD (WINAPI *pMFCdll_OneWORD_ThreeChar)(char * a , char * b ,char * c);  //返回WORD
typedef WORD (WINAPI *pMFCdll_OneWORD_FourChar)  (char * a , char * b ,char * c ,char * d);  //返回WORD
typedef WORD (WINAPI *pMFCdll_OneWORD_FiveChar)  (char * a , char * b ,char * c ,char * d ,char * e);  //返回WORD
typedef WORD (WINAPI *pMFCdll_OneWORD_SixChar)  (char * a , char * b ,char * c ,char * d ,char * e,char * f);  //返回WORD

/************************************************************************/
/*易语言:字符串接口  <返回值,CString>(文本型 a, 整数型 b,整数型 c,整数型 d,整数型 e,整数型 f)*/
/***********************************************************************/
typedef char * (WINAPI *pMFCdll_OneChar_OneChar)  (char *);  //返回cahr *
typedef char * (WINAPI *pMFCdll_OneChar_TwoChar)  (char * , char *);  //返回cahr *
typedef char * (WINAPI *pMFCdll_OneChar_ThreeChar)  (char * , char * ,char *);  //返回cahr *
typedef char * (WINAPI *pMFCdll_OneChar_FourChar)  (char * , char * ,char * ,char *);  //返回cahr *
typedef char * (WINAPI *pMFCdll_OneChar_FiveChar)  (char * , char * ,char * ,char * ,char *);  //返回cahr *
typedef char * (WINAPI *pMFCdll_OneChar_SixChar)  (char * , char * ,char * ,char * ,char * ,char *);  //返回cahr *

typedef char * (WINAPI *pMFCdll_OneChar_OneWORD)  (WORD a);  //返回cahr *
typedef char * (WINAPI *pMFCdll_OneChar_TwoWORD)  (WORD a , WORD b);  //返回cahr *
typedef char * (WINAPI *pMFCdll_OneChar_ThreeWORD)  (WORD a , WORD b ,WORD c);  //返回cahr *
typedef char * (WINAPI *pMFCdll_OneChar_FourWORD)  (WORD a , WORD b ,WORD c ,WORD d);  //返回cahr *
typedef char * (WINAPI *pMFCdll_OneChar_FiveWORD)  (WORD a , WORD b ,WORD c ,WORD d ,WORD e);  //返回cahr *
typedef char * (WINAPI *pMFCdll_OneChar_SixWORD)  (WORD a , WORD b ,WORD c ,WORD d ,WORD e,WORD f);  //返回cahr *

/************************************************************************/
/*易语言使用外部定义
/***********************************************************************/
extern pMFCdll_OneVOID_OneVOID    MFCdll_OneVOID_OneVOID;
extern pMFCdll_OneWORD_OneVOID    MFCdll_OneWORD_OneVOID;
extern pMFCdll_OneCHAR_OneVOID    MFCdll_OneCHAR_OneVOID;


extern pMFCdll_OneWORD_OneWORD    MFCdll_OneWORD_OneWORD;
extern pMFCdll_OneWORD_TwoWORD    MFCdll_OneWORD_TwoWORD;
extern pMFCdll_OneWORD_ThreeWORD  MFCdll_OneWORD_ThreeWORD;
extern pMFCdll_OneWORD_FourWORD    MFCdll_OneWORD_FourWORD;
extern pMFCdll_OneWORD_FiveWORD    MFCdll_OneWORD_FiveWORD;
extern pMFCdll_OneWORD_SixWORD    MFCdll_OneWORD_SixWORD;


extern pMFCdll_OneWORD_OneChar    MFCdll_OneWORD_OneChar;
extern pMFCdll_OneWORD_TwoChar    MFCdll_OneWORD_TwoChar;
extern pMFCdll_OneWORD_ThreeChar  MFCdll_OneWORD_ThreeChar;
extern pMFCdll_OneWORD_FourChar    MFCdll_OneWORD_FourChar;
extern pMFCdll_OneWORD_FiveChar    MFCdll_OneWORD_FiveChar;
extern pMFCdll_OneWORD_SixChar    MFCdll_OneWORD_SixChar;


extern pMFCdll_OneChar_OneChar    MFCdll_OneChar_OneChar;
extern pMFCdll_OneChar_TwoChar    MFCdll_OneChar_TwoChar;
extern pMFCdll_OneChar_ThreeChar  MFCdll_OneChar_ThreeChar;
extern pMFCdll_OneChar_FourChar    MFCdll_OneChar_FourChar;
extern pMFCdll_OneChar_FiveChar    MFCdll_OneChar_FiveChar;
extern pMFCdll_OneChar_SixChar    MFCdll_OneChar_SixChar;


extern pMFCdll_OneChar_OneWORD    MFCdll_OneChar_OneWORD;
extern pMFCdll_OneChar_TwoWORD    MFCdll_OneChar_TwoWORD;
extern pMFCdll_OneChar_ThreeWORD  MFCdll_OneChar_ThreeWORD;
extern pMFCdll_OneChar_FourWORD    MFCdll_OneChar_FourWORD;
extern pMFCdll_OneChar_FiveWORD    MFCdll_OneChar_FiveWORD;
extern pMFCdll_OneChar_SixWORD    MFCdll_OneChar_SixWORD;


#endif    //MFCCLOADDLL_H

3、这里为不带Dlg的那个项目文件

// testDll.cpp : 定义应用程序的类行为。
//

#include "stdafx.h"
#include "testDll.h"
#include "testDllDlg.h"

#include "LoadDLL.h"

//*************原来的代码不动******************

BOOL CtestDllApp::InitInstance()
{  
    //这里上面不动,下面加载DLL,就是游戏读条一样的,现在只有一个
  if(LoadDll("C://Users//Administrator//Desktop//ZJDLLV1.0.3.dll") == FALSE)
  {

    AfxMessageBox("ZJDLLV1.0.3.dll,加载失败!");
    AfxGetMainWnd()->CloseWindow();    
  }
  else
  {
    AfxMessageBox("ZJDLLV1.0.3.dll,加载成功!");
  }
    //下面系统的
  CtestDllDlg dlg;
  m_pMainWnd = &dlg;
  INT_PTR nResponse = dlg.DoModal();
  if (nResponse == IDOK)
  {
    // TODO: 在此放置处理何时用
    // “确定”来关闭对话框的代码
  }
  else if (nResponse == IDCANCEL)
  {
    // TODO: 在此放置处理何时用
    // “取消”来关闭对话框的代码
  }

  // 删除上面创建的 shell 管理器。
  if (pShellManager != NULL)
  {
    delete pShellManager;
  }

  // 由于对话框已关闭,所以将返回 FALSE 以便退出应用程序,
  // 而不是启动应用程序的消息泵。
  return FALSE;
}

4、这里带Dlg的那个项目文件

#include "LoadDLL.h"
//-------中间的不动---------
//这里是按钮单机自动生成的槽函数
void CtestDllDlg::OnBnClickedOk()
{ 
  WORD reslut = MFCdll_OneWORD_SixWORD(2017,9,7,15,23,0);

  if(reslut == 1)
  {
    AfxMessageBox("软件可正常使用!");
  }
  else if(reslut == 0)
  {
    AfxMessageBox("软件已过期!");
  }

  AfxMessageBox(MFCdll_OneCHAR_OneVOID());
}

5、教程结束。

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI