// InProcServerDemo *pInProcServer; // try{pInProcServer=createInProcServer(pUnkOuter,riid,mWinConsole);} // catch(InProcServerDemo::InProcServerDemoNoInterface){return ComResult::NoInterface;} // catch(...){return ComResult::UnExpected;} // if(0!=pInstanceItem) // { // mServer.up(); // comResult.result(pInProcServer->QueryInterface(riid,ppv)); // if(comResult.isFailure()) // { // mServer.down(); // ::delete pInProcServer; // } // } // else comResult.result(ComResult::OutOfMemory); // } // return comResult.result(); #if 0 SafeArrayAllocData HRESULT SafeArrayAllocData(SAFEARRAY FAR* psa); Allocates memory for a safe array, based on a descriptor created with SafeArrayAllocDescriptor. Parameter psa Pointer to an array descriptor created by SafeArrayAllocDescriptor. Return Value The return value obtained from the returned HRESULT is one of the following. Return value Meaning S_OK Success. E_INVALIDARG The argument psa was not a valid safe array descriptor. E_UNEXPECTED The array could not be locked. Example The following example creates a safe array using the SafeArrayAllocDescriptor and SafeArrayAllocData functions. SAFEARRAY FAR* FAR*ppsa; unsigned int ndim = 2; HRESULT hresult = SafeArrayAllocDescriptor(ndim, ppsa); if( FAILED(hresult))     return ERR_OutOfMemory; (*ppsa)->rgsabound[ 0 ].lLbound = 0; (*ppsa)->rgsabound[ 0 ].cElements = 5; (*ppsa)->rgsabound[ 1 ].lLbound = 1; (*ppsa)->rgsabound[ 1 ].cElements = 4; hresult = SafeArrayAllocData(*ppsa); if( FAILED(hresult)) {     SafeArrayDestroyDescriptor(*ppsa)     return ERR_OutOfMemory; } See Also SafeArrayDestroyData, SafeArrayDestroyDescriptor SafeArrayAllocDescriptor HRESULT SafeArrayAllocDescriptor(      unsigned int cDims,     SAFEARRAY FAR* FAR* ppsaOut    ); Allocates memory for a safe array descriptor. Parameters cDims The number of dimensions of the array. ppsaOut Pointer to a location in which to store the created array descriptor. Return Value The return value obtained from the returned HRESULT is one of the following. Return value Meaning S_OK Success. E_INVALIDARG The argument psa was not a valid safe array descriptor. E_UNEXPECTED The array could not be locked. Comments This function allows the creation of safe arrays that contain elements with data types other than those provided by SafeArrayCreate. After creating an array descriptor using SafeArrayAllocDescriptor, set the element size in the array descriptor, an call SafeArrayAllocData to allocate memory for the array elements. Example The following example creates a safe array using the SafeArrayAllocDescriptor and SafeArrayAllocData functions. SAFEARRAY FAR* FAR*ppsa; unsigned int ndim = 2; HRESULT hresult = SafeArrayAllocDescriptor( ndim, ppsa ); if( FAILED( hresult ) )     return ERR_OutOfMemory; (*ppsa)->rgsabound[ 0 ].lLbound = 0; (*ppsa)->rgsabound[ 0 ].cElements = 5; (*ppsa)->rgsabound[ 1 ].lLbound = 1; (*ppsa)->rgsabound[ 1 ].cElements = 4; hresult = SafeArrayAllocData( *ppsa ); if( FAILED( hresult ) ) {     SafeArrayDestroyDescriptor( *ppsa )     return ERR_OutOfMemory; } #endif tMap[::GetCurrentThread()]=1; // int data=iMap[h1]; return FALSE; } #if 0 #include #include #include #include #include #include #include int PASCAL WinMain(HINSTANCE hInstance,HINSTANCE /*hPrevInstance*/,LPSTR /*lpszCmdLine*/,int /*nCmdShow*/) { ComObj comObj; ComResult comResult; ServerInfo serverInfo(String("rocinante")); BString string; MultiQuery multiQuery; Variant variant; multiQuery.size(1); multiQuery[0].pIID=&IID_IRemoteProcess; comResult=comObj.createInstance(CLSID_CoRemoteProcess,0,ClassContext(LocalServer|RemoteServer),serverInfo,multiQuery); if(!comResult.success()) { ComResult::Facility facility=comResult.facility(); WORD comError(comResult.error()); return 0; } if(!ComResult(multiQuery[0].hr).success())return 0; IRemoteProcess *pIRemoteProcess=(IRemoteProcess*)multiQuery[0].pItf; // pIRemoteProcess->GetRemoteProcesses(&variant.getVARIANT()); pIRemoteProcess->Snapshot(&variant.getVARIANT()); int processCount(0); variant.getData(VTInt4,(void*)&processCount); variant.clear(); pIRemoteProcess->GetProcessFirst(&variant.getVARIANT()); variant.clear(); for(int index=0;indexGetModuleFirst(&variant.getVARIANT()); if(VTInt4==variant.getType())variant.clear(); else { BString string; variant.getData(string); ::OutputDebugString(string.toString()+String("\n")); variant.clear(); while(true) { pIRemoteProcess->GetModuleNext(&variant.getVARIANT()); if(VTInt4==variant.getType()) { variant.clear(); break; } else { BString string; variant.getData(string); ::OutputDebugString(string.toString()+String("\n")); variant.clear(); } } } pIRemoteProcess->GetProcessNext(&variant.getVARIANT()); variant.clear(); } pIRemoteProcess->Release(); // pIRemoteProcess->GetRemoteProcesses(&variant.getVARIANT()); // variant.getData(string); // ::OutputDebugString(string.toString()+String("\n")); return 0; } #if 0 #if 0 ProcessAPI psAPI; Console winConsole; ProcessInfoList processInfoList; psAPI.enumProcesses(processInfoList); for(int pindex=0;pindexGetTime(&varDate); // } variantTime=varDate; variantTime.getTime(systemTime); pIRemoteTime->Release(); #endif #endif #if 0 ComObj comObj; ServerInfo serverInfo; MultiQuery multiQuery; SystemTime systemTime; VariantTime variantTime; DATE varDate; for(int index=0;index<50000000;index++) { Variant variant; if(!variant.changeType(VTBStr))::OutputDebugString("error changing type\n"); BString str("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"); variant.setData(str); } #endif #if 0 ArrayBound bounds(50); Array accessor; SafeArray safeArray; // short sint2(90); // short *psint2; BString string; wchar_t *str=0; UINT arrayExtents; safeArray.create(VTBStr,bounds); int dimensions(safeArray.getDimensions()); accessor.size(1); accessor[0]=0; // string="hello"; // if(!safeArray.setAt(accessor,(void*)string.str()))::OutputDebugString("error setting element\n"); // if(!safeArray.setAt(accessor,(void*)&sint2))::OutputDebugString("error setting element\n"); if(!safeArray.setAt(accessor,(void*)L"hello"))::OutputDebugString("error setting element\n"); safeArray.lock(); safeArray.getPtrOfIndex(accessor,(void**)&str); int strLen=::SysStringByteLen(str); safeArray.unlock(); #endif #endif PureBitmap pureBitmap; pureBitmap.windowBitmap(::GetDesktopWindow()); GlobalData bitmapBytes; WORD width; WORD height; WORD widthBytes; WORD bitsPerPixel; width=pureBitmap.width(); height=pureBitmap.height(); widthBytes=pureBitmap.widthBytes(); bitsPerPixel=pureBitmap.bitsPerPixel(); pureBitmap.getBitmapBits(bitmapBytes); HWND hWnd=::CreateWindow("BUTTON","",WS_VISIBLE|WS_POPUP,CW_USEDEFAULT,CW_USEDEFAULT,640,480,(HWND)0,(HMENU)0,::GetModuleHandle(0),0); if(!hWnd)return 0; ::ShowWindow(hWnd,SW_SHOW); ::UpdateWindow(hWnd); PureDevice pureDevice(hWnd); PureDevice compatibleDevice; compatibleDevice.compatibleDevice(pureDevice); compatibleDevice.select(pureBitmap.getBitmap(),true); pureDevice.stretchBlt(Rect(0,0,320,200),compatibleDevice,Rect(0,0,pureBitmap.width(),pureBitmap.height())); ::Sleep(10000); ::DestroyWindow(hWnd); #endif STDMETHODIMP RemoteProcess::GetDesktopWindow(VARIANT *pVariant) { SafeArray safeArray; ArrayBound arrayBound; int *pData; arrayBound.elements(100); safeArray.create(VTInt4,arrayBound); safeArray.accessData((void**)&pData); for(int index=0;index<100;index++)pData[index]=index; safeArray.unaccessData(); safeArray.disposition(SafeArray::Assume); ::VariantInit(pVariant); pVariant->vt=VT_ARRAY; pVariant->parray=safeArray.getSAFEARRAY(); return ComResult::Success; }