========================================================================
    NetRockey4 class library for VC.Net 
========================================================================

1.Register NetRY4Com.dll. (using Regsvr32.exe, or call routines in NetRY4Com.dll).
2.Include below header file in your program:

#include "comdef.h"			//Include this for _variant_t.
#include "NetRY4Com_i.c"	//Include this for IID_INetRockey4,IID_INetRy4Util,CLISD_CNetRockey4
#include "NetRY4Com.h"		//Include this for INetRockey4.
#include "NR4ComDef.h"		//Include this for error code definations.	


Pay attention to file sequence, you'll get an compile error if your include them in wrong sequence. NetRy4Com_i.c include the defination of GUIDs,you only need include it once. NetRy4Com.h include defination of INetRockey4. 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. NR4ComDef.h include defination of NetRockey4 command and NetRy4Com return code. Caution: The return code of NetRy4COM is NOT same as NetRockey4 API. The rule of new return code is : HIWORD is 0x8030,LOWORD is return code of NetRockey4 API.


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


HRESULT			hRet;
INetRockey4*	pRy4=NULL;
INetRy4Util*	pNetUtil=NULL;


//Create INetRockey4 interface.
hRet=CoCreateInstance(CLSID_CNetRockey4,NULL,CLSCTX_INPROC_SERVER,IID_INetRockey4,(void**)&pRy4);
if(FAILED(hRet))
{
	//...
}

//Query INetRy4Util Interface.
hRet=pRy4->QueryInterface(IID_INetRy4Util,(void**)&pNetUtil);
if(FAILED(hRet))
{
	//...	
}



5.Call Release routine when the interface is nouse.

if(pRy4)		pRy4->Release();
if(pNetUtil)	pNetUtil->Release();
CoUninitialize();

6.INetRockey4.DoCmd Usage:

(1)define variable as below.

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_FIND			[out]				Return a BSTR string stored the name of server. You can use "_bstr_t bsSvrName=vaBuffer" to get value, and use "wprintf(L"%s",(BSTR)bsSvrName)" to print.

RY_FIND_NEXT	[out]				Just same as RY_FIND.

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.



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.
