========================================================================
    Rockey4 class library for VC.Net 
========================================================================

1.
Manual install Ry4Com.dll -- regsvr32 Ry4Com.dll
Manual uninstall Ry4Com.dll -- regsvr32 /u Ry4Com.dll

(RockeyControlVal.ocx is in the "\\Api32\COM\\" directory)
or call routines in Ry4Com.dll.
2.Include below header file in your program:

#include "comdef.h"
#include "Ry4Com_i.c"
#include "Ry4Com.h"
#include "Ry4ComDef.h"


Pay attention to file sequence, you'll get an compile error if your include them in wrong sequence.. Ry4Com_i.c include the defination of GUIDs,you only need include it once . Ry4Com.h include defination of IRockey4. comdef.h include defination of _variant_t. The usage of _variant_t is just same as VARIANT, and you can obtain additional convenience if you use it. Ry4ComDef.h include defination of Rockey4 command and Ry4Com return code. Caution: The return code of Ry4COM is NOT same as Rockey4 API. The rule of new return code is : HIWORD is 0x8030,LOWORD is return code of Rockey4 API


3.Call "CoInitialize(NULL);" before using IRockey4 , and add "CoUninitialize()" before exiting your program.
4.After call CoInitialize, add below codes to your program:


HRESULT		hRet;
IRockey4*	pRy4=NULL;


//Create IRockey4 Interface.
hRet=CoCreateInstance(CLSID_CRockey4,NULL,CLSCTX_INPROC_SERVER,IID_IRockey4,(void**)&pRy4);
if(FAILED(hRet))
{
	//...
}



5.Call Release routine when the interface is nouse.

if(pRy5)	pRy5->Release();
if(pVersion)	pVersion->Release();
CoUninitialize();

6.IRockey4.DoCmd Usage:

(1)定义要使用的变量

DWORD		lp1=0,lp2=0;				//long parameters, please see manual
WORD		p1=0,p2=0,p3=0,p4=0;			//short parameters,please see manual
WORD 		handle=0				//Handle of opened device.
_variant_t	vaBuffer=(int)0;			//_variant_t to store byte array or BSTR.
							//Caution: you can use _variant_t as VARIANT.

(2)vaBuffer details:

vaBuffer ONLY used by below commands:

Command	   		obBuffer direction	Data type

RY_READ	   		[out]			Return a Byte array,stored UDZ information.You can use "UseVariantData" routine to get byte array.
RY_WRITE   		[in]                 	Set to a byte array, stored UDZ information. You can use "ByteArray2Variant" routine to copy an array to _variant_t.
RY_WRITE_ARITHMETIC	[in]			Set to a arithmetic wide char string. vaBuffer=(BSTR)L"This is a test" to set a BSTR string.

In other commands, you can set it to 0 by line "vaBuffer=(int)0;" to improve efficiency.


//Below routines can conver Byte array to _variant_t, or conver _variant_t to byte array.

//Convert byte array to Variant type

VARIANT ByteArray2Variant(BYTE* pSrc,DWORD dwLen)
{
	VARIANT			vRet;
	SAFEARRAYBOUND	sab;

	sab.lLbound=0;
	sab.cElements=dwLen;

	vRet.vt=VT_ARRAY|VT_UI1;		
	vRet.parray=SafeArrayCreate(VT_UI1,1,&sab);

	BYTE* pArrayData=NULL;

	SafeArrayAccessData(vRet.parray,(void**)&pArrayData);

	memcpy(pArrayData,pSrc,dwLen);

	SafeArrayUnaccessData(vRet.parray);

	return vRet;
}

//Get byte array from VARIANT.
BYTE* UseVariantData(VARIANT& vt,DWORD* pLength=NULL)
{
	BYTE* pRet=NULL;	

	SafeArrayAccessData(vt.parray,(void**)&pRet);

	if(pLength)
	{
		*pLength=vt.parray->rgsabound[0].cElements;
	}	

	return pRet;
}

void UnUseVariantData(VARIANT& vt)
{
	SafeArrayUnaccessData(vt.parray);
}

see vc7Sample.cpp to get more usage details.
