Aug 14

There was recently a question posted on the COM forum here at CodeProject and it involved a temporary VARIANT object being created (in a VB client code) to fill an [in, out, optional] VARIANT* parameter of a method call.

The person who posted the original question was one GuimaSun and his COM server code was listed as follows :


STDMETHODIMP CDCSClient::CallService( VARIANT *p1 )
{
...
...

VariantClear( p );
VariantInit( p );
p->vt = VT_BSTR | VT_BYREF;
BSTR *pBSTR = new BSTR;
*pBSTR = SysAllocString( L”abc” );
p->pbstrVal = pBSTR;



}

His VB client code was :

For i = 1 To 1000
Dim myInt As Integer
myInt = 3
ret = client.CallService(myInt)
Next

Apparently, his COM server code was changing the Variant Type of the input VARIANT pointer “p” and assigning it to contain a BSTR.

His VB code experienced memory leaks due to the BSTR (created inside his COM CallService() method) not being ::SysFreeString()’ed.

After much discussion with several members of the forum, Vi2 came up with a code suggestion for GuimaSun as follows :

STDMETHODIMP CDCSClient::CallService(/*[in,out]*/ VARIANT *p)
{
if (V_VT(p) == (VT_VARIANT | VT_BYREF))
{
// only here you can change the type of passed variable (see VB example below)
VARIANT *p2 = V_VARIANTREF(p);
p2->vt = VT_BSTR;
p2->bstrVal = SysAllocString( L"abc" );
return S_OK;
}
}

Dim v As Variant
v = 1
Debug.Print TypeName(v) & ” ” & v
Call obj.CallService(v)
Debug.Print TypeName(v) & ” ” & v

Basically, only a VARIANT of Variant Type (VT_VARIANT | VT_BYREF) can be modified to be of a different VT.

_______________________
Tip Courtesy :- Lim Bio Liong

Aug 09

This link my help :- http://www.lvr.com/usbfaq.htm

Jul 04

XML Paper Specification: Overview

The XML Paper Specification (XPS) provides users and developers with a robust, open and trustworthy format for electronic paper. The XML Paper Specification describes electronic paper in a way that can be read by hardware, read by software, and read by people. XPS documents print better, can be shared easier, are more secure and can be archived with confidence.

The XML Paper Specification itself is platform independent, openly published, and available royalty-free and Microsoft has integrated XPS-based technologies into Microsoft Windows Vista operating system and the 2007 Microsoft Office system. Microsoft brings additional document value to its customers, partners, and the computing industry through the XPS-based technologies.

Above text copied from MSDN

 Read rest here

Tagged with:
Jul 01

1. COM Spy console that allows you to spy applications using COM interfaces:
http://www.nektra.com/products/deviare/comconsole/index.php

The COM Spy application is based on Deviare hook library so all you can see in the console can be done by code from any language supporting COM. Source code of this application is available.

2. Another one :

http://staff.develop.com/jasonw/comspy/default.htm

3. Yet another open sourced COM spy :

http://jacquelin.potier.free.fr/winapioverride32/

_______________________
Tip Courtesy :-  Lim Bio Liong

Jul 01

Check out this link from Microsoft KB. Again why reinvent the wheel :-)

Jul 01

Naveen responded with this very useful piece of code using CTimeSpan and CTime MFC classes.

// Get Time in second for one day.
CTimeSpan sPan(0,0,0, 86400 );// 1 day
// Get current time
CTime CurTime = CTime::GetCurrentTime();
// add time span to current time
CurTime += sPan;
// calculate and show your new date
CString csTime = CurTime.Format(_T(”%A, %B %d, %Y”));
AfxMessageBox( csTime );

Jun 23

* If you define an interface in a Type Library and implement it in Visual Basic, no problem.

* For example, if you define an interface ITestInterface in a Type Library and then have your VB ActiveX project reference this type lib, the following statement goes fine :

Implements ITestInterface

* However, if you define a source (i.e. event) interface in a Type Library and try to have a Visual Basic ActiveX raise its events via RaiseEvent statements, not possible.

* For example, if you define a dispinterface _ITestEvents with event Event01() in a Type Library and then have your VB ActiveX Project raise it as follows :

RaiseEvent Event01()

The VB Compiler will complain of an unidentified event.

If you try to raise it as follows :

RaiseEvent <typelibraryname>.Event01()

The compiler will not complain but it still won’t work. The problem is that _ITestEvents will not be recognized as being a source interface of the ActiveX.

* If we try to define the events of _ITestEvents in the declaration of the ActiveX itself, e.g. :

Public Event Event01()

The ActiveX will then declare a source interface for itself and Event01() will be absorbed into this default source event set, i.e. you will find the following declarations when you observe the TLB generated for the ActiveX :

coclass clsVBActiveX
{
...
...
...
[default, source] dispinterface __clsVBActiveX;
};




dispinterface __clsVBActiveX
{
void Event01();
};

_______________________
Tip Courtesy :-  Lim Bio Liong

preload preload preload