3,245
社区成员
发帖
与我相关
我的任务
分享
#include "stdafx.h"
#include "Call_client.h"
#include "test_MainTest.h"
#include <string>
#include "Sub.h"
#include "CDclient.h"
#include < atlbase.h >
#include "CReply.h"
#import "client.ocx"
#ifdef _DEBUG
#define new DEBUG_NEW
#endif
BEGIN_MESSAGE_MAP(CCall_clientApp, CWinApp)
END_MESSAGE_MAP()
// CCall_clientApp construction
CCall_clientApp::CCall_clientApp()
{
// TODO: add construction code here,
// Place all significant initialization in InitInstance
}
// The one and only CCall_clientApp object
CCall_clientApp theApp;
// CCall_clientApp initialization
BOOL CCall_clientApp::InitInstance()
{
CWinApp::InitInstance();
return TRUE;
}
JNIEXPORT jstring JNICALL Java_test_MainTest_call_1queryPoints(JNIEnv *jenv, jclass jobj, jstring jstr)
{
typedef HRESULT (WINAPI * FREG)();
std::string str("Empty");
jstring result = jenv->NewStringUTF(str.c_str());
HMODULE hDll = ::LoadLibrary(_T("D:/Microsoft/Project/Call_client/debug/client.ocx"));
if (hDll == NULL)
{
std::string str("Load client.ocx Fail !");
result = jenv->NewStringUTF(str.c_str());
return result;
}
FREG lpfunc = (FREG) ::GetProcAddress(hDll, "DllRegisterServer");
if (lpfunc == NULL)
{
std::string str("No Function Found !");
result = jenv->NewStringUTF(str.c_str());
return result;
}
HRESULT hr = lpfunc();
if (hr!=S_OK)
{
std::string str("Get HRESULT :hr !");
result = jenv->NewStringUTF(str.c_str());
}
//初始化
CoInitialize(NULL);
到这里就不知道该怎么初始化这个ocx对象了,于是就用下面的方法(就是被包围的地方,在mfc下面可用,dll下面不能用)
////////////////////////////////////////////////////////
//CRect rect;
//CDclient* cd = new CDclient();
//cd->Create(_T(""), NULL, rect, NULL, 0);
///////////////////////////////////////////////////////
const char* tp = jenv->GetStringUTFChars(jstr,0);
CString key(tp);
这里调用了client.ocx中的方法
VARIANT vrs = cd->GetRestPoint(key);
//////////////////////////////////////////////////////////////////////////
这后面的先不管
VARIANT vars[2];
vars[0].vt =VT_BSTR;
vars[1].vt =VT_BSTR;
long index = 0;
HRESULT hr = ::SafeArrayGetElement(vrs.parray,&index,&vars[index]);
index = 1;
HRESULT hr1 = ::SafeArrayGetElement(vrs.parray,&index,&vars[index]);
BSTR s = vars[0].bstrVal;
BSTR s1 = vars[1].bstrVal;
LPCWSTR lpw = (LPCWSTR)s1;
int size = WideCharToMultiByte(CP_ACP,0,lpw,-1,0,0,NULL,NULL);
//////////////////////////////////////////////////////////////////////////
return result;
}
// CDclient.h : Declaration of ActiveX Control wrapper class(es) created by Microsoft Visual C++
#pragma once
/////////////////////////////////////////////////////////////////////////////
// CDclient
class CDclient : public CWnd
{
protected:
DECLARE_DYNCREATE(CDclient)
public:
CLSID const& GetClsid()
{
static CLSID const clsid
= { 0xCD6ACDB8, 0x8EE0, 0x4C6A, { 0x83, 0x14, 0x73, 0x2, 0x6B, 0x7E, 0x7A, 0xEB } };
return clsid;
}
virtual BOOL Create(LPCTSTR lpszClassName, LPCTSTR lpszWindowName, DWORD dwStyle,
const RECT& rect, CWnd* pParentWnd, UINT nID,
CCreateContext* pContext = NULL)
{
return CreateControl(GetClsid(), lpszWindowName, dwStyle, rect, pParentWnd, nID);
}
BOOL Create(LPCTSTR lpszWindowName, DWORD dwStyle, const RECT& rect, CWnd* pParentWnd,
UINT nID, CFile* pPersist = NULL, BOOL bStorage = FALSE,
BSTR bstrLicKey = NULL)
{
return CreateControl(GetClsid(), lpszWindowName, dwStyle, rect, pParentWnd, nID,
pPersist, bStorage, bstrLicKey);
}
// Attributes
public:
// Operations
VARIANT GetRestPoint(LPCTSTR aUserKey)
{
VARIANT result;
static BYTE parms[] = VTS_BSTR ;
InvokeHelper(0x3, DISPATCH_METHOD, VT_VARIANT, (void*)&result, parms, aUserKey);
return result;
}
。。。。