Files
Work/com/scraps.txt
2024-08-07 09:12:07 -04:00

457 lines
8.9 KiB
Plaintext
Raw Permalink Blame History

This file contains invisible Unicode characters
This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
// 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 <Picture>
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 <Picture>
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 <common/windows.hpp>
#include <com/bstring.hpp>
#include <com/variant.hpp>
#include <com/sarray.hpp>
#include <com/com.hpp>
#include <remoteps/remoteps_i.c>
#include <remoteps/remoteps.h>
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;index<processCount;index++)
{
pIRemoteProcess->GetModuleFirst(&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;pindex<processInfoList.size();pindex++)
{
for(int mindex=0;mindex<processInfoList[pindex].size();mindex++)
{
winConsole.writeLine((processInfoList[pindex])[mindex].moduleFileName());
}
}
winConsole.read();
ComObj comObj;
ComResult comResult;
ServerInfo serverInfo(String("rocinante"));
MultiQuery multiQuery;
SystemTime systemTime;
VariantTime variantTime;
DATE varDate;
multiQuery.size(1);
multiQuery[0].pIID=&IID_IRemoteTime;
comResult=comObj.createInstance(CLSID_CoRemoteTime,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;
IRemoteTime *pIRemoteTime=(IRemoteTime*)multiQuery[0].pItf;
// for(int i=0;i<100000;i++)
// {
pIRemoteTime->GetTime(&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<long> 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<BYTE> 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;
}