mycomclient.cpp

来自「java的com编程包」· C++ 代码 · 共 60 行

CPP
60
字号
#include <jni.h>
#include "HelloCom.h"
#include <stdio.h>
#include "..\Java_COM_ATL\Java_COM_ATL.h"
#include <iostream.h>

JNIEXPORT void JNICALL Java_HelloCom_HelloCom_1function
  (JNIEnv *, jobject)
{
	 

// Copy the following from the Java_COM_ATL_i.c file
// from the Java_COM_ATL project directory
//This number may be diff. as it generated by VC++ using uuidgen.exe.

	const IID IID_IJcom = {0x665A282D,0x3ECD,0x11D5,{0xAC,0x5C,0xDF,0xF9,0xE8,0x6D,0xD6,0x2D}};
	const CLSID CLSID_Jcom = {0x665A282E,0x3ECD,0x11D5,{0xAC,0x5C,0xDF,0xF9,0xE8,0x6D,0xD6,0x2D}};

// Declare and HRESULT and a pointer to the Java_COM_ATL interface
	HRESULT			hr;
	IJcom		*IJComAtl;

	// Now we will intilize COM
	hr = CoInitialize(0);

	// Use the SUCCEEDED macro and see if we can get a pointer 
	// to the interface
	if(SUCCEEDED(hr))
	{
		hr = CoCreateInstance( CLSID_Jcom, NULL, CLSCTX_INPROC_SERVER,
						IID_IJcom, (void**) &IJComAtl);
		
		// If we succeeded then call the AddNumbers method, if it failed
		// then display an appropriate message to the user.
		if(SUCCEEDED(hr))
		{
			long ReturnValue;

			hr = IJComAtl->AddNumbers(5, 7, &ReturnValue);
			cout << "The answer for 5 + 7 is: " << ReturnValue << endl;
			hr = IJComAtl->Release();  
		}
		else
		{
			printf("CoCreateInstance Failed.");
		}
	}
	// Uninitialize COM
	CoUninitialize();

    printf("Hello Com is ok and over!\n");
    return;
}






⌨️ 快捷键说明

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