|
Did you try RegisterClass() /RegisterClassEx() ?
If your target platform is windows 2000 and later, you can create message only windows. They work like windows, except they have no graphical representations. They're just "identities" (HWND).
Good music: In my rosary[^]
|
|
|
|
|
I was using AfxRegisterClass() and CWnd::CreateEx()
After changing the code to use RegisterClassEx( ) and CreateWindowEx(), everything now seems to work.
What the difference might be, I have no idea.
Thanks for the clue.
Shraddhan
|
|
|
|
|
You're most welcome, and I'm glad that it worked out for you.
Good music: In my rosary[^]
|
|
|
|
|
Hi,
How can I load a char** into a VARIANT?
thanks
|
|
|
|
|
Hello bvais,
I assume that you want to use a VARIANT to store a receiver of a string. You can't load a char** into a VARIANT. The standard way to pass strings in COM is to use BSTRs.
Try using a BSTR* instead. In this case, the type for your VARIANT would be : (VT_BSTR|VT_BY_REF). The specific member in the VARIANT to use is "pbstrVal" (set/get via the V_BSTRREF() macro).
Best of luck,
Bio.
|
|
|
|
|
Hi Bio,
I need to pass an array of strings. How do I do that?
|
|
|
|
|
|
Hello bvais,
Yes, as mentioned by GuimaSun (in an earlier reply), the way to do this is to use a SAFEARRAY of BSTRs.
I have a sample function below that can help you to achieve this :
// CreateSafeArrayFromBSTRArray()
// This function will create a SafeArray of BSTRs using the BSTR elements
// found inside
// the first parameter "pBSTRArray".
//
// Note well that the output SafeArray will contain COPIES of the original
// BSTRs
// inside the input parameter "pBSTRArray".
//
long CreateSafeArrayFromBSTRArray
(
BSTR* pBSTRArray,
ULONG ulArraySize,
SAFEARRAY** ppSafeArrayReceiver
)
{
HRESULT hrRetTemp = S_OK;
SAFEARRAY* pSAFEARRAYRet = NULL;
SAFEARRAYBOUND rgsabound[1];
ULONG ulIndex = 0;
long lRet = 0;
// Initialise receiver.
if (ppSafeArrayReceiver)
{
*ppSafeArrayReceiver = NULL;
}
if (pBSTRArray)
{
rgsabound[0].lLbound = 0;
rgsabound[0].cElements = ulArraySize;
pSAFEARRAYRet = (SAFEARRAY*)SafeArrayCreate
(
(VARTYPE)VT_BSTR,
(unsigned int)1,
(SAFEARRAYBOUND*)rgsabound
);
}
for (ulIndex = 0; ulIndex < ulArraySize; ulIndex++)
{
long lIndexVector[1];
lIndexVector[0] = ulIndex;
// Since pSAFEARRAYRet is created as a SafeArray of VT_BSTR,
// SafeArrayPutElement() will create a copy of each BSTR
// inserted into the SafeArray.
SafeArrayPutElement
(
(SAFEARRAY*)pSAFEARRAYRet,
(long*)lIndexVector,
(void*)(pBSTRArray[ulIndex])
);
}
if (pSAFEARRAYRet)
{
*ppSafeArrayReceiver = pSAFEARRAYRet;
}
return lRet;
}
Then, you can use the above function in your code as demonstrated below :
#include <comdef.h>
int main()
{
// Define an array of BSTRs which are initialized via _bstr_t.
BSTR bstrArray[] =
{
_bstr_t(L"BSTR 01").copy(),
_bstr_t(L"BSTR 02").copy(),
_bstr_t(L"BSTR 03").copy(),
_bstr_t(L"BSTR 04").copy(),
_bstr_t(L"BSTR 05").copy()
};
SAFEARRAY* pSAFEARRAY = NULL;
// Create a Safe Array of BSTRs which are copies of the elements
// of bstrArray.
CreateSafeArrayFromBSTRArray
(
bstrArray,
sizeof(bstrArray)/sizeof(BSTR),
&pSAFEARRAY
);
// Destroy the safe array object pSAFEARRAY.
// SafeArrayDestroy() will also destroy the
// BSTRs created via CreateSafeArrayFromBSTRArray().
// pSAFEARRAY.
SafeArrayDestroy(pSAFEARRAY);
pSAFEARRAY = NULL;
return 0;
}
Best Regards,
Bio.
|
|
|
|
|
Lim Bio Liong wrote:
_bstr_t(L"BSTR 01").copy()
Just out of curiosity.. why this, when there's SysAllocString() ?
Good music: In my rosary[^]
|
|
|
|
|
Hello Jorgen,
Yes, Jorgen, SysAllocString() should be used. I recently used _bstr_t in a similar manner (for R&D purposes) as the sample code for bvais and developed something of a habit .
Thanks for pointing it out, Jorgen.
Best Regards,
Bio.
|
|
|
|
|
I am using TotalRecorder(ww.highcriteria.com) in my application developed in C#. My Application inetract with TotalRecorder through COM. Total Recorder provides a sample in VC 6.0 for saving the recorded file at a specified folder location. I have converted the VC 6.0 code to C#, everything is working fine except when i call the method that saves the recorded files, the method takes variant as input, while the wrapper for this method generated by VS 2003 takes object as input. I passed him with the required parameters but it gives error 'Method Not Implemented'. Both the codes are given below. Please help me in conerting this VC code (variants) to C# (objects)
This is the code in VC 6.0
_variant_t vartFileName;
VARIANT vFmt;
vartFileName = cFileName;
vFmt.vt = VT_ERROR;
vFmt.scode = DISP_E_PARAMNOTFOUND;
g_pTRDoc->SaveAs(vartFileName, vFmt);
I have converted this in C# like this
string FileName = "c:\test.wav";
rec.ActiveDocument.SaveAs(FileName,System.Reflection.Missing.Value);
Thanks
I am using TotalRecorder(ww.highcriteria.com) in my application developed in C#. My Application inetract with TotalRecorder through COM. Total Recorder provides a sample in VC 6.0 for saving the recorded file at a specified folder location. I have converted the VC 6.0 code to C#, everything is working fine except when i call the method that saves the recorded files, the method takes variant as input, while the wrapper for this method generated by VS 2003 takes object as input. I passed him with the required parameters but it gives error 'Method Not Implemented'. Both the codes are given below. Please help me in conerting this VC code (variants) to C# (objects)
This is the code in VC 6.0
_variant_t vartFileName;
VARIANT vFmt;
vartFileName = cFileName;
vFmt.vt = VT_ERROR;
vFmt.scode = DISP_E_PARAMNOTFOUND;
g_pTRDoc->SaveAs(vartFileName, vFmt);
I have converted this in C# like this
string FileName = "c:\test.wav";
rec.ActiveDocument.SaveAs(FileName,System.Reflection.Missing.Value);
Thanks
Basit Tanveer
Software Engineer
|
|
|
|
|
|
U have the source code ? If yes u can debug using dll host !
|
|
|
|
|
hi all
i have 2 .lib files related to one com server . the first is to make connection with the server and the latter is for sending and recieving data .
i have created an instance for the first by :
<br />
MULTI_QI qi[] = { & __uuidof(IserverSys) , 0, 0} ;<br />
<br />
COSERVERINFO serverinfo;<br />
COSERVERINFO *pServerInfo = 0;<br />
memset( &serverinfo, 0, sizeof( COSERVERINFO ) );<br />
<br />
serverinfo.pwszName = NULL;
pServerInfo = &serverinfo;<br />
serverinfo.pAuthInfo=NULL;<br />
{<br />
hr = ::CoCreateInstanceEx( <br />
__uuidof(serverSys) , <br />
0, <br />
CLSCTX_LOCAL_SERVER | CLSCTX_REMOTE_SERVER ,<br />
pServerInfo, <br />
1, <br />
qi<br />
);<br />
if( ( FAILED(qi[0].hr) ) || ( FAILED(hr) ) )<br />
{ <br />
AfxMessageBox(" Could not create instance of server");<br />
return ;<br />
}<br />
g_pIserverSys = (IserverSys *) qi[0].pItf;<br />
do i have to do the same for the latter ? if not what do i must do to create an object for the latter?
|
|
|
|
|
Is it possibly to obain currently active IE window using IShellWindows. I can get the list of open explorer windows using get_Count() function that's about it.
What I want is to keep track of multiple opened IE windows, so that if the window becomes active (a user navigates to a new site, etc) I can jusp directly to it, retreive and retreive the document witout cycling through all opened IE windows.
Thank you
|
|
|
|
|
Are you writing a BHO ? If so you could sink events from IWebBrowserEvents2 interface to get notified from new browser windows and page navigation, there's a lot of articles on codeproject describing how to do it.
I hope it helps,
GuimaSun
www.nexsun.com.br
NEXSUN TechZone
|
|
|
|
|
i have a com class in an mfc dialog based app that recieves data from an out of process com server . i want to send the reciveing data to a dialog to show it . what is the best way ? posting message or another ?
|
|
|
|
|
A general solution is to launch an event with data from the COM object, that event would be subscribed by the MFC client which get the data and may show it.
GuimaSun
www.nexsun.com.br
NEXSUN TechZone
|
|
|
|
|
Hello, I hope I am posting this in the right place.
I am writing a website using Asp.Net and I am trying to use a COM written in FoxPro. I have compiled the COM as a multi-threaded dll and added it as a reference. When I try to instantiate it (e.g. myserver.myclass comObject = new myclass() ), I get a InteropServices.COMException and the Message is simply "Exception Occurred". Does anyone know what I might be doing wrong, or any way I can get more information out of the exception? I tried printing the HRESULT and I get -2146352567.
Any help would be appreciated.
Thanks
BCKY
|
|
|
|
|
Hi all
I am writng an application in mfc which have to monitor the internet explorer
and to get the x and y coordinates of the caret position.
I already knows how to get IHTMLDocument2 from the HWND
but was not able to figure out how to get the position of the caret inside the document.
i understood that the IHTMLCaret cannot be retrieve because my application is in a different process.
So what is the solution for this
i will be very happey to hear any suggestion because i am stuck with this problem for almost two weeks
now.
|
|
|
|
|
Hi all ,
I have created an instance of a COM+ component in another component . All works extremely fine in Debug Version but when compiled in Release version , the Release (.Release()) of the component gives an access violation exception .
Can anyone please help me solve this problem .
Thanks and Best Regards,
Amey
|
|
|
|
|
|
Hi GaimaSun ,
Ya, tht's the first thing tht i've tried , problem is that there memory corruption somewhere which is getting overlooked in the debug version but as release version optimises memory allocations, its giving an access violation while releasing the inner component . Thinking of using purify for this problem, wht's ur suggesion .
thanks for ur response.
Best Regards,
Amey
|
|
|
|
|
To add RTP render filter CLSID_RTPRenderFilter what library can I add to project?
Mau
|
|
|
|
|
Hello,
I have a class that contains a Shell Folder and PIDL. The class instances live in the .Tag of TreeView and ListView items. When a Drag containing file/directory information (as in dragged from Windows Explorer) is over or drops on one of the TreeViewNodes, I want to respond using the IDropTarget Interface of the Folder represented by my class instance.
My problem is that I cannot get the IDropTarget Interface to work. I suspect that I have either mis-defined it or have omitted some vital step prior to using it.
Specifics:
<ComImportAttribute(), _
InterfaceType(ComInterfaceType.InterfaceIsIUnknown), _
Guid("00000122-0000-0000-C000-000000000046")> _
Public Interface IDropTarget
<PreserveSig()> _
Function DragEnter( _
ByVal pDataObj As System.Windows.Forms.IDataObject, _
ByVal grfKeyState As Integer, _
ByVal pt As POINT, _
ByRef pdwEffect As System.Windows.Forms.DragDropEffects) _
As Integer
<PreserveSig()> _
Function DragOver( _
ByVal grfKeyState As Integer, _
ByRef pt As POINT, _
ByRef pdwEffect As System.Windows.Forms.DragDropEffects) _
As Integer
<PreserveSig()> _
Function DragLeave()
<PreserveSig()> _
Function DragDrop( _
ByVal pDataObj As System.Windows.Forms.IDataObject, _
ByVal grfKeyState As Integer, _
ByRef pt As POINT, _
ByRef pdwEffect As System.Windows.Forms.DragDropEffects) _
As Integer
End Interface
Note: I am only calling DragEnter so far in my code.
Where POINT is declared:
<StructLayout(LayoutKind.Sequential)> _
Public Structure POINT
Dim x As Integer
Dim y As Integer
End Structure
The part that seems to work:
... code that sets up relPidl ...
Dim apidl(0) as IntPtr
apidl(0) = relPidl
Dim Eff As Integer
Dim theInterface As IDropTarget
Dim HR As Integer
HR = Me.Parent.m_Folder.GetUIObjectOf(IntPtr.Zero, 1, apidl, ShellDll.IID_IDropTarget, Eff, theInterface)
If HR <> 0 Then
Marshal.ThrowExceptionForHR(HR)
End If
Note: m_Folder is the shell Folder interface of the Folder that contains the Folder of interest. Folder & PIDL code has been working for months, though this is the first time I've used GetUIObjectOf. In any event the returned item is a System_ComObject, just like I expect.
The part that doesn't work:
... e is a System.Windows.Forms.DragEventArgs with valid data..
for example the DragEventArgs generated by dragging from Windows Explorer ...
...The target is a normal Windows directory reporting .IsDropTarget among its attributes ...
Dim IDrop As IDropTarget = target.GetDropTargetOf()
If Not IsNothing(IDrop) Then
Dim scrpt As New ShellDll.POINT()
scrpt.x = e.X
scrpt.y = e.Y
Dim eff As DragDropEffects = e.AllowedEffect
Try
Dim res As Integer = IDrop.DragEnter(CType(e.Data, IDataObject), e.KeyState, scrpt, eff)
Catch ex As Exception
Debug.WriteLine(ex.ToString)
End Try
System.Runtime.InteropServices.Marshal.ReleaseComObject(IDrop)
End If
Always throws a NullReference exception after reporting:
A first chance exception of type 'System.NullReferenceException' occurred in exptreelib.dll
Additional information: Object reference not set to an instance of an object.
I strongly suspect some kind of Marshalling problem on the return from IDropTarget, but I will believe any explanation that works.
Thanks
Jim Parsells
|
|
|
|
|