IDM com api ,about the safearray
I am new one to VB and know few about the safearray
Code:#import "IDManTypeInfo.tlb" #include "IDManTypeInfo.h" #include "IDManTypeInfo_i.c" #include <atlbase.h> //for CComBSTR class int main(int argc, char* argv[]) { int nItems = 2; CComBSTR referer = L"http://www.internetdownloadmanager.com/"; CComBSTR href1 = L"http://www.internetdownloadmanager.com/trans_kit.zip"; CComBSTR cookie1 = L"cookie1=aaa"; CComBSTR descr1 = L"Link 1"; CComBSTR href2 = L"http://www.internetdownloadmanager.com/idman406.exe"; CComBSTR cookie2 = L"cookie2=bbb"; CComBSTR descr2 = L"Link 2"; CComBSTR userAgent = L"User-Agent test2"; CoInitialize(NULL); ICIDMLinkTransmitter2* pIDM; HRESULT hr = CoCreateInstance(CLSID_CIDMLinkTransmitter, NULL, CLSCTX_LOCAL_SERVER, IID_ICIDMLinkTransmitter2, (void**)&pIDM); if (S_OK == hr) { SAFEARRAY *pSA = NULL; SAFEARRAYBOUND bound[3]; bound[0].lLbound = 0; bound[0].cElements = nItems; bound[1].lLbound = 0; bound[1].cElements = 4; pSA = SafeArrayCreate(VT_BSTR, 2, bound); if (NULL != pSA) { long index[2]; int iItem = 0; index[0] = iItem; index[1] = 0; SafeArrayPutElement(pSA, index, href1); index[1] = 1; SafeArrayPutElement(pSA, index, cookie1); index[1] = 2; SafeArrayPutElement(pSA, index, descr1); index[1] = 3; SafeArrayPutElement(pSA, index, ((0 == iItem) ? userAgent : NULL)); iItem++; index[0] = iItem; index[1] = 0; SafeArrayPutElement(pSA, index, href2); index[1] = 1; SafeArrayPutElement(pSA, index, cookie2); index[1] = 2; SafeArrayPutElement(pSA, index, descr2); index[1] = 3; SafeArrayPutElement(pSA, index, ((0 == iItem) ? userAgent : NULL)); VARIANT var; VariantInit(&var); var.vt = VT_ARRAY | VT_BSTR; var.parray = pSA; hr = pIDM->SendLinksArray(referer, &var); if (S_OK != hr) { //......... } SafeArrayDestroy(pSA); } pIDM->Release(); } CoUninitialize(); return 0; }
so i write some code
but run errorCode:Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (pDst As Any, pSrc As Any, ByVal ByteLen As Long) Private Declare Function VarPtr Lib "MSVBVM60" (var As Any) As Long Private Declare Function ArrPtr Lib "MSVBVM60" Alias "VarPtr" (arr() As Any) As Long Dim params() Private Type SafeArray cDims As Integer fFeatures As Integer cbElements As Long cLocks As Long pvData As Long cElements As Long lLbound As Long End Type Private Sub Command1_Click() Dim referer As String ReDim Preserve params(1, 3) Dim pSafeArray As Long Dim MyArr As SafeArray Dim idmobj As CIDMLinkTransmitter params(0, 3) = "User-Agent test2" params(0, 1) = "http://www.internetdownloadmanager.com/trans_kit.zip" params(0, 2) = "cookie1=aaa" params(0, 3) = "Link 1" params(1, 1) = "http://www.internetdownloadmanager.com/idman404.exe" params(1, 2) = "cookie2=bbb" params(1, 3) = "Link 2" referer = "http://www.internetdownloadmanager.com/" CopyMemory pSafeArray, ByVal ArrPtr(params), 4 CopyMemory MyArr, ByVal pSafeArray, 24 Set idmobj = CreateObject("IDMan.CIDMLinkTransmitter") idmobj.SendLinksArray referer, VarPtr(MyArr) end sub
someone help me




Reply With Quote