mirror of
https://github.com/ultimatepp/ultimatepp.git
synced 2026-05-21 06:45:39 -06:00
+Ole: SAFEARRAY constructor helpers
+TCore: SQL-style extensions to calculator parser git-svn-id: svn://ultimatepp.org/upp/trunk@2546 f0d560ea-af0d-0410-9eb7-867de7ffcac7
This commit is contained in:
parent
9531e3a220
commit
dace14ec23
6 changed files with 217 additions and 66 deletions
|
|
@ -258,7 +258,7 @@ bool OcxTypeInfo::CanUnload() const
|
|||
RDUMP(object_count);
|
||||
RDUMP(refcount);
|
||||
RDUMP(lock_count);
|
||||
return object_count == 0 && refcount <= 1 && lock_count <= 0;
|
||||
return object_count == 0 && refcount <= 2 && lock_count <= 0;
|
||||
}
|
||||
|
||||
int OcxTypeInfo::IncRef()
|
||||
|
|
@ -718,10 +718,16 @@ void ExeRunServer()
|
|||
}
|
||||
LOGSYSOCX("-> registration OK");
|
||||
|
||||
MSG msg;
|
||||
while(GetMessage(&msg, 0, 0, 0)) {
|
||||
TranslateMessage(&msg);
|
||||
DispatchMessage(&msg);
|
||||
int ms = msecs();
|
||||
bool quit = false;
|
||||
while(!quit) {
|
||||
if(msecs(ms) >= 2000) {
|
||||
if(OcxTypeLib::Get().CanUnload())
|
||||
break;
|
||||
ms = msecs();
|
||||
}
|
||||
if(!Ctrl::ProcessEvent(&quit))
|
||||
Sleep(10);
|
||||
}
|
||||
LOGSYSOCX("end of message loop");
|
||||
OcxTypeLib::Get().RevokeObjects();
|
||||
|
|
|
|||
|
|
@ -247,12 +247,24 @@ ValueArray SAFEARRAYToValueArray(SAFEARRAY *array)
|
|||
return SAFEARRAYToValueArrayPart(array, indices.Begin(), ndims - 1);
|
||||
}
|
||||
|
||||
SAFEARRAY * ValueArrayToSAFEARRAY(const ValueArray& varray)
|
||||
Vector<WString> SAFEARRAYToWStringVector(SAFEARRAY *array)
|
||||
{
|
||||
SAFEARRAYBOUND rgsabound;
|
||||
rgsabound.lLbound = 0;
|
||||
rgsabound.cElements = varray.GetCount();
|
||||
SAFEARRAY *a = SafeArrayCreate(VT_VARIANT, 1, &rgsabound);
|
||||
Vector<WString> out;
|
||||
out.SetCount(array->rgsabound[0].cElements);
|
||||
Vector<long> indices;
|
||||
indices.SetCount(array->cDims, 0);
|
||||
for(int i = 0; i < out.GetCount(); i++) {
|
||||
OleBstr s;
|
||||
indices[0] = i;
|
||||
HRESULT hr = SafeArrayGetElement(array, indices.Begin(), s.Set());
|
||||
out[i] = s;
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
SAFEARRAY *ToSAFEARRAY(const ValueArray& varray)
|
||||
{
|
||||
SAFEARRAY *a = SafeArrayCreateVector(VT_VARIANT, 0, varray.GetCount());
|
||||
if(!a)
|
||||
return NULL;
|
||||
for(long index = 0; index < varray.GetCount(); index++) {
|
||||
|
|
@ -262,6 +274,18 @@ SAFEARRAY * ValueArrayToSAFEARRAY(const ValueArray& varray)
|
|||
return a;
|
||||
}
|
||||
|
||||
SAFEARRAY *ToSAFEARRAY(const Vector<WString>& vstr)
|
||||
{
|
||||
SAFEARRAY *a = SafeArrayCreateVector(VT_BSTR, 0, vstr.GetCount());
|
||||
if(!a)
|
||||
return NULL;
|
||||
for(long index = 0; index < vstr.GetCount(); index++) {
|
||||
OleBstr var = vstr[(int)index];
|
||||
SafeArrayPutElement(a, &index, ~var);
|
||||
}
|
||||
return a;
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
// special types
|
||||
|
||||
|
|
|
|||
|
|
@ -84,6 +84,24 @@ inline String AsString(const Guid& guid) { return Format(~guid); }
|
|||
inline bool operator == (const Guid& a, const Guid& b) { return ~a == ~b; }
|
||||
inline bool operator != (const Guid& a, const Guid& b) { return ~a != ~b; }
|
||||
|
||||
class OleExc : public Exc
|
||||
{
|
||||
public:
|
||||
OleExc(HRESULT hresult);
|
||||
OleExc(HRESULT hresult, const char *text);
|
||||
|
||||
public:
|
||||
HRESULT hresult;
|
||||
};
|
||||
|
||||
HRESULT LogResult(HRESULT hr);
|
||||
HRESULT LogError(HRESULT hr);
|
||||
|
||||
inline void OleVerify(HRESULT hr) { if(FAILED(hr)) throw OleExc(hr); }
|
||||
inline void OleVerify(HRESULT hr, const char *text) { if(FAILED(hr)) throw OleExc(hr, text); }
|
||||
|
||||
#define OLE_VERIFY(c) OleVerify(c, #c)
|
||||
|
||||
class OleVariant : public VARIANT
|
||||
{
|
||||
public:
|
||||
|
|
@ -124,9 +142,29 @@ void ReturnWString(BSTR *dest, WString s);
|
|||
HRESULT CheckReturnWString(BSTR *bstr, WString s);
|
||||
|
||||
ValueArray SAFEARRAYToValueArray(SAFEARRAY *array);
|
||||
SAFEARRAY *ValueArrayToSAFEARRAY(const ValueArray& varray);
|
||||
void ReturnValueArray(SAFEARRAY *dest, const ValueArray& array);
|
||||
HRESULT CheckReturnString(BSTR *bstr, String s);
|
||||
Vector<WString> SAFEARRAYToWStringVector(SAFEARRAY *array);
|
||||
SAFEARRAY *ToSAFEARRAY(const ValueArray& varray);
|
||||
SAFEARRAY *ToSAFEARRAY(const Vector<WString>& varray);
|
||||
void ReturnSAFEARRAY(SAFEARRAY *dest, const ValueArray& array);
|
||||
void ReturnSAFEARRAY(SAFEARRAY *dest, const Vector<WString>& array);
|
||||
HRESULT CheckReturnSAFEARRAY(SAFEARRAY *dest, const ValueArray& array);
|
||||
HRESULT CheckReturnSAFEARRAY(SAFEARRAY *dest, const Vector<WString>& array);
|
||||
|
||||
class OleSafeArray {
|
||||
public:
|
||||
OleSafeArray() : array(NULL) {}
|
||||
OleSafeArray(const ValueArray& va) { array = ToSAFEARRAY(va); }
|
||||
OleSafeArray(const Vector<WString>& vs) { array = ToSAFEARRAY(vs); }
|
||||
OleSafeArray(const OleSafeArray& a) { array = NULL; if(a.array) OleVerify(SafeArrayCopy(a.array, &array)); }
|
||||
~OleSafeArray() { if(array) SafeArrayDestroy(array); }
|
||||
|
||||
operator ValueArray () const { return SAFEARRAYToValueArray(array); }
|
||||
operator Vector<WString> () const { return SAFEARRAYToWStringVector(array); }
|
||||
SAFEARRAY *operator ~ () const { return array; }
|
||||
|
||||
private:
|
||||
SAFEARRAY *array;
|
||||
};
|
||||
|
||||
class OleBstr
|
||||
{
|
||||
|
|
@ -157,24 +195,6 @@ Color PackColor(long rgb);
|
|||
long UnpackColor(Color c);
|
||||
HRESULT CheckReturnColor(long *ptr, Color c);
|
||||
|
||||
class OleExc : public Exc
|
||||
{
|
||||
public:
|
||||
OleExc(HRESULT hresult);
|
||||
OleExc(HRESULT hresult, const char *text);
|
||||
|
||||
public:
|
||||
HRESULT hresult;
|
||||
};
|
||||
|
||||
HRESULT LogResult(HRESULT hr);
|
||||
HRESULT LogError(HRESULT hr);
|
||||
|
||||
inline void OleVerify(HRESULT hr) { if(FAILED(hr)) throw OleExc(hr); }
|
||||
inline void OleVerify(HRESULT hr, const char *text) { if(FAILED(hr)) throw OleExc(hr, text); }
|
||||
|
||||
#define OLE_VERIFY(c) OleVerify(c, #c)
|
||||
|
||||
template <class T>
|
||||
class IRefBase : Moveable< IRefBase<T> >
|
||||
{
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue