⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 testocxctl.cpp

📁 java中实现jni调用,jni调用dll ,dll再调用dll ,dll显示调用
💻 CPP
字号:
// TestOCXCtl.cpp : Implementation of the CTestOCXCtrl ActiveX Control class.

#include "stdafx.h"
#include "testOCX.h"
#include "TestOCXCtl.h"
#include "TestOCXPpg.h"


#include "windows.h"

typedef int ( * lpAddFun)(int,int);

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif


IMPLEMENT_DYNCREATE(CTestOCXCtrl, COleControl)


/////////////////////////////////////////////////////////////////////////////
// Message map

BEGIN_MESSAGE_MAP(CTestOCXCtrl, COleControl)
	//{{AFX_MSG_MAP(CTestOCXCtrl)
	// NOTE - ClassWizard will add and remove message map entries
	//    DO NOT EDIT what you see in these blocks of generated code !
	//}}AFX_MSG_MAP
	ON_OLEVERB(AFX_IDS_VERB_PROPERTIES, OnProperties)
END_MESSAGE_MAP()


/////////////////////////////////////////////////////////////////////////////
// Dispatch map

BEGIN_DISPATCH_MAP(CTestOCXCtrl, COleControl)
	//{{AFX_DISPATCH_MAP(CTestOCXCtrl)
	DISP_FUNCTION(CTestOCXCtrl, "getShort", getShort, VT_I2, VTS_NONE)
	//}}AFX_DISPATCH_MAP
	DISP_FUNCTION_ID(CTestOCXCtrl, "AboutBox", DISPID_ABOUTBOX, AboutBox, VT_EMPTY, VTS_NONE)
END_DISPATCH_MAP()


/////////////////////////////////////////////////////////////////////////////
// Event map

BEGIN_EVENT_MAP(CTestOCXCtrl, COleControl)
	//{{AFX_EVENT_MAP(CTestOCXCtrl)
	// NOTE - ClassWizard will add and remove event map entries
	//    DO NOT EDIT what you see in these blocks of generated code !
	//}}AFX_EVENT_MAP
END_EVENT_MAP()


/////////////////////////////////////////////////////////////////////////////
// Property pages

// TODO: Add more property pages as needed.  Remember to increase the count!
BEGIN_PROPPAGEIDS(CTestOCXCtrl, 1)
	PROPPAGEID(CTestOCXPropPage::guid)
END_PROPPAGEIDS(CTestOCXCtrl)


/////////////////////////////////////////////////////////////////////////////
// Initialize class factory and guid

IMPLEMENT_OLECREATE_EX(CTestOCXCtrl, "TESTOCX.TestOCXCtrl.1",
	0xed52cfff, 0x55ef, 0x4894, 0xbe, 0xc3, 0x57, 0x5, 0xca, 0x7b, 0xaa, 0x6)


/////////////////////////////////////////////////////////////////////////////
// Type library ID and version

IMPLEMENT_OLETYPELIB(CTestOCXCtrl, _tlid, _wVerMajor, _wVerMinor)


/////////////////////////////////////////////////////////////////////////////
// Interface IDs

const IID BASED_CODE IID_DTestOCX =
		{ 0x8578973d, 0x51a5, 0x4252, { 0x8f, 0xc4, 0x16, 0xc8, 0x39, 0x2f, 0xcc, 0xc3 } };
const IID BASED_CODE IID_DTestOCXEvents =
		{ 0x23c6a444, 0x3e3c, 0x447a, { 0x99, 0x37, 0xc, 0x9d, 0xb4, 0x33, 0x65, 0x81 } };


/////////////////////////////////////////////////////////////////////////////
// Control type information

static const DWORD BASED_CODE _dwTestOCXOleMisc =
	OLEMISC_ACTIVATEWHENVISIBLE |
	OLEMISC_SETCLIENTSITEFIRST |
	OLEMISC_INSIDEOUT |
	OLEMISC_CANTLINKINSIDE |
	OLEMISC_RECOMPOSEONRESIZE;

IMPLEMENT_OLECTLTYPE(CTestOCXCtrl, IDS_TESTOCX, _dwTestOCXOleMisc)


/////////////////////////////////////////////////////////////////////////////
// CTestOCXCtrl::CTestOCXCtrlFactory::UpdateRegistry -
// Adds or removes system registry entries for CTestOCXCtrl

BOOL CTestOCXCtrl::CTestOCXCtrlFactory::UpdateRegistry(BOOL bRegister)
{
	// TODO: Verify that your control follows apartment-model threading rules.
	// Refer to MFC TechNote 64 for more information.
	// If your control does not conform to the apartment-model rules, then
	// you must modify the code below, changing the 6th parameter from
	// afxRegApartmentThreading to 0.

	if (bRegister)
		return AfxOleRegisterControlClass(
			AfxGetInstanceHandle(),
			m_clsid,
			m_lpszProgID,
			IDS_TESTOCX,
			IDB_TESTOCX,
			afxRegApartmentThreading,
			_dwTestOCXOleMisc,
			_tlid,
			_wVerMajor,
			_wVerMinor);
	else
		return AfxOleUnregisterClass(m_clsid, m_lpszProgID);
}


/////////////////////////////////////////////////////////////////////////////
// CTestOCXCtrl::CTestOCXCtrl - Constructor

CTestOCXCtrl::CTestOCXCtrl()
{
	InitializeIIDs(&IID_DTestOCX, &IID_DTestOCXEvents);

	// TODO: Initialize your control's instance data here.
}


/////////////////////////////////////////////////////////////////////////////
// CTestOCXCtrl::~CTestOCXCtrl - Destructor

CTestOCXCtrl::~CTestOCXCtrl()
{
	// TODO: Cleanup your control's instance data here.
}


/////////////////////////////////////////////////////////////////////////////
// CTestOCXCtrl::OnDraw - Drawing function

void CTestOCXCtrl::OnDraw(
			CDC* pdc, const CRect& rcBounds, const CRect& rcInvalid)
{
	// TODO: Replace the following code with your own drawing code.
	pdc->FillRect(rcBounds, CBrush::FromHandle((HBRUSH)GetStockObject(WHITE_BRUSH)));
	pdc->Ellipse(rcBounds);
}


/////////////////////////////////////////////////////////////////////////////
// CTestOCXCtrl::DoPropExchange - Persistence support

void CTestOCXCtrl::DoPropExchange(CPropExchange* pPX)
{
	ExchangeVersion(pPX, MAKELONG(_wVerMinor, _wVerMajor));
	COleControl::DoPropExchange(pPX);

	// TODO: Call PX_ functions for each persistent custom property.

}


/////////////////////////////////////////////////////////////////////////////
// CTestOCXCtrl::OnResetState - Reset control to default state

void CTestOCXCtrl::OnResetState()
{
	COleControl::OnResetState();  // Resets defaults found in DoPropExchange

	// TODO: Reset any other control state here.
}


/////////////////////////////////////////////////////////////////////////////
// CTestOCXCtrl::AboutBox - Display an "About" box to the user

void CTestOCXCtrl::AboutBox()
{
	CDialog dlgAbout(IDD_ABOUTBOX_TESTOCX);
	dlgAbout.DoModal();
}


/////////////////////////////////////////////////////////////////////////////
// CTestOCXCtrl message handlers

short CTestOCXCtrl::getShort() 
{
	// TODO: Add your dispatch handler code here
	HINSTANCE hDll;   //DLL句柄	
	lpAddFun addFun;  //函数指针
    hDll = LoadLibrary(".\\dllTest.dll");
    int result=0;
	if (hDll != NULL)
	{
		addFun = (lpAddFun)GetProcAddress(hDll,"add");	
		if(addFun!=NULL)
		{
		    result =  addFun(2,3);    
			//printf("%d",result);
		}
		FreeLibrary(hDll);
	}
	return (short)result;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -