|
Dear All,
Iam new to c# window application and also for COM.I have a COM component
which is developed in Visual Basic.Now i want to use this component into
my c# window application.How can i register and use.The COM is in the form
of EXE not in the form of DLL.Please help me out on this.
Thanks & Regards
Veeresh
i want to join this group
|
|
|
|
|
Hello,
I have a C# com object (.net framework 2.0) that I want to call from C++.
I tried to import the tlb and create the object using MyNamespace::IMyInterfacePtr pObj ; but i got errors about not impelemting queryInterface, AddRef etc.
I found out that I should use CComObject (ref: http://support.microsoft.com/kb/181265[^].
So declaring the variable was a success using:
<codeccomobject><mynamespace::mycomclass xmlns:mynamespace="#unknown">* pObj;Now I am trying to create an instance by using:
<code>HRESULT hRes = (CComObject<mynamespace::mycomclass>::CreateInstance(&pObj);</mynamespace::mycomclass>But I get the following error:
c:\program files\microsoft visual studio\vc98\atl\include\atlcom.h(2395) : error C2504: 'MyConClass' : base class undefined<br />
see reference to class template instantiation 'ATL::CComObject<struct>;' being compiled</struct>
Any ideas what I am doing wrong?
thanks!
|
|
|
|
|
Your question is confusing as hell.
When you say that:
"I have a C# com object (.net framework 2.0) that I want to call from C++.
I tried to import the tlb and create the object using MyNamespace::IMyInterfacePtr pObj; but i got errors about not impelemting queryInterface, AddRef etc."
I have to wonder, obviously, not only how did you define this object, but, why would you refer to this object as a COM object (since, by definition, a COM object must implement the IUnknown interface methods, QueryInterface, AddRef, Release).
(...just curious,...)
Everything I know about COM. I learned from Behind The Scenes of a COM Server[^]
|
|
|
|
|
Hi,
I have COM module which run as local server on invocation by the client.
I have Cisco Security Agent installed on my machine. When I run my client which onvokes COM module.I can run the requests and COM module will give the result. Once I get the result this COM module will be removed which is not suppose to. I cannot run some other requests again because COM module will not be there. This happens only with Cisco Security agent installed on the machine not even you need to run this service.If it just installed on your machine it gives you problem.COM module should go only when Client closes. IF CSA(Cisco Security Agent) is not installed on the machine this perfectly works fine.Any idea why this hehaves like this?
Please help.
|
|
|
|
|
Does anybody know how to hook IWiaDevMgr?
I wanna to do something before user EnumDeviceInfo().
|
|
|
|
|
How to add a neew interface to an existing COM application?
Regards,
KDevloper
|
|
|
|
|
i crate a class CAudio, which implementes from IStream, and it's code like below:
#include "objidl.h"
#ifndef INCLUDE_AUDIOSTREAM
#define INCLUDE_AUDIOSTREAM
class CAudioStream :
public IStream
{
private:
LONG m_cRef;
HANDLE m_hFile;
public:
CAudioStream(TCHAR* pszFileName);
~CAudioStream(void);
HRESULT STDMETHODCALLTYPE QueryInterface(REFIID riid, void** ppvObject);
ULONG STDMETHODCALLTYPE AddRef(void);
ULONG STDMETHODCALLTYPE Release(void);
HRESULT STDMETHODCALLTYPE Read(void *pv, ULONG cb, ULONG *pcbRead);
HRESULT STDMETHODCALLTYPE Write(const void *pv, ULONG cb, ULONG *pcbWritten);
HRESULT STDMETHODCALLTYPE Seek(LARGE_INTEGER dlibMove, DWORD dwOrigin, ULARGE_INTEGER *plibNewPosition);
HRESULT STDMETHODCALLTYPE SetSize(ULARGE_INTEGER libNewSize);
HRESULT STDMETHODCALLTYPE CopyTo(IStream *pstm, ULARGE_INTEGER cb, ULARGE_INTEGER *pcbRead, ULARGE_INTEGER *pcbWritten);
HRESULT STDMETHODCALLTYPE Commit(DWORD grfCommitFlags);
HRESULT STDMETHODCALLTYPE Revert(void);
HRESULT STDMETHODCALLTYPE LockRegion(ULARGE_INTEGER libOffset, ULARGE_INTEGER cb, DWORD dwLockType);
HRESULT STDMETHODCALLTYPE UnlockRegion(ULARGE_INTEGER libOffset, ULARGE_INTEGER cb, DWORD dwLockType);
HRESULT STDMETHODCALLTYPE Stat(STATSTG *pstatstg, DWORD grfStatFlag);
HRESULT STDMETHODCALLTYPE Clone(IStream **ppstm);
};
#endif
#include "StdAfx.h"
#include "AudioStream.h"
CAudioStream::CAudioStream(TCHAR* pszFileName)
{
m_cRef = 0;
m_hFile = CreateFile(pszFileName, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING,
FILE_ATTRIBUTE_ARCHIVE | FILE_ATTRIBUTE_NORMAL, NULL);
if(m_hFile == INVALID_HANDLE_VALUE)
MessageBox(GetActiveWindow(), "can not open file.", "error", MB_OK);
}
CAudioStream::~CAudioStream(void)
{
if(m_hFile != INVALID_HANDLE_VALUE)
CloseHandle(m_hFile);
m_hFile = INVALID_HANDLE_VALUE;
}
HRESULT STDMETHODCALLTYPE CAudioStream::QueryInterface(const IID &riid, void **ppvObject)
{
if(IID_IStream == riid || IID_IUnknown == riid)
{
*ppvObject = static_cast<IStream*>(this);
AddRef();
return S_OK;
}
*ppvObject = NULL;
return E_NOINTERFACE;
}
ULONG STDMETHODCALLTYPE CAudioStream::AddRef()
{
return InterlockedIncrement(&m_cRef);
}
ULONG STDMETHODCALLTYPE CAudioStream::Release()
{
if(InterlockedDecrement(&m_cRef) == 0)
{
delete this;
return S_OK;
}
return m_cRef;
}
HRESULT STDMETHODCALLTYPE CAudioStream::Read(void *pv, ULONG cb, ULONG *pcbRead)
{
if(!ReadFile(m_hFile, pv, cb, pcbRead, NULL))
return E_FAIL;
if(*pcbRead <= 0)
return E_FAIL;
return S_OK;
}
HRESULT STDMETHODCALLTYPE CAudioStream::Write(const void *pv, ULONG cb, ULONG *pcbWritten)
{
if(!WriteFile(m_hFile, pv, cb, pcbWritten, NULL))
return E_FAIL;
if(*pcbWritten <= 0)
return E_FAIL;
return S_OK;
}
HRESULT STDMETHODCALLTYPE CAudioStream::Seek(LARGE_INTEGER dlibMove, DWORD dwOrigin, ULARGE_INTEGER *plibNewPosition)
{
plibNewPosition->QuadPart = SetFilePointer(m_hFile, dlibMove.LowPart, NULL, dwOrigin);
return S_OK;
}
HRESULT STDMETHODCALLTYPE CAudioStream::SetSize(ULARGE_INTEGER libNewSize)
{
SetFilePointer(m_hFile, libNewSize.LowPart, NULL, 0);
return S_OK;
}
HRESULT STDMETHODCALLTYPE CAudioStream::CopyTo(IStream *pstm, ULARGE_INTEGER cb, ULARGE_INTEGER *pcbRead, ULARGE_INTEGER *pcbWritten)
{
return -1;
}
HRESULT STDMETHODCALLTYPE CAudioStream::Commit(DWORD grfCommitFlags)
{
return -1;
}
HRESULT STDMETHODCALLTYPE CAudioStream::Revert(void)
{
return -1;
}
HRESULT STDMETHODCALLTYPE CAudioStream::LockRegion(ULARGE_INTEGER libOffset, ULARGE_INTEGER cb, DWORD dwLockType)
{
return -1;
}
HRESULT STDMETHODCALLTYPE CAudioStream::UnlockRegion(ULARGE_INTEGER libOffset, ULARGE_INTEGER cb, DWORD dwLockType)
{
return -1;
}
HRESULT STDMETHODCALLTYPE CAudioStream::Stat(STATSTG *pstatstg, DWORD grfStatFlag)
{
pstatstg->cbSize.QuadPart = GetFileSize(m_hFile, NULL);
pstatstg->grfLocksSupported = 0;
return -1;
}
HRESULT STDMETHODCALLTYPE CAudioStream::Clone(IStream **ppstm)
{
return -1;
}
test code like below:
#include "stdafx.h"
#include "AudioStream.h"
int main(int argc, char* argv[])
{
CoInitialize(NULL);
CAudioStream* pAudioStream = NULL;
IWMSyncReader* reader;
HRESULT hr;
hr = WMCreateSyncReader(NULL, 0, &reader);
if(hr != S_OK)
{
CoUninitialize();
return 0;
}
pAudioStream = new CAudioStream("d:\\Music\\You&Me.mp3");
IStream* pStream = static_cast<IStream*>(pAudioStream);
pStream->AddRef();
hr = reader->OpenStream(pStream);
if(hr != S_OK)
{
LARGE_INTEGER dlibMove;
ULARGE_INTEGER plibNewPosition;
dlibMove.QuadPart = 30;
plibNewPosition.QuadPart = 0;
pAudioStream->Seek(dlibMove, FILE_BEGIN, &plibNewPosition);
hr = reader->OpenStream(pStream);
if(hr != S_OK)
{
reader->Release();
reader = NULL;
pStream->Release();
pStream = NULL;
CoUninitialize();
return 0;
}
DWORD dwOutputCount;
hr = reader->GetOutputCount(&dwOutputCount);
if(hr != S_OK)
{
reader->Release();
reader = NULL;
pStream->Release();
pStream = NULL;
CoUninitialize();
return 0;
}
printf("OutputCount=%d\n", dwOutputCount);
}
system("pause");
reader->Release();
reader = NULL;
pStream->Release();
pStream = NULL;
CoUninitialize();
return 0;
}
the code exit at IStream::OpenStream after IStream::Seek, what error occurred?
|
|
|
|
|
to run code, need include:
#include <stdio.h>
#include <stdlib.h>
#include <windows.h>
#include <wmsdk.h>
and import wmvcore.lib.
|
|
|
|
|
Hi,
This code is returning error "class not registred", how could I correct it
IStorage *Storage;
CLSID clsidWord;
CoInitialize(NULL);
HRESULT hr=CoCreateInstance(clsidWord,NULL,CLSCTX_SERVER,IID_IStorage,(void**) &Storage);
|
|
|
|
|
where is clsidWord defined?
|
|
|
|
|
I want to passe object parameter to c#.net, thanks!
|
|
|
|
|
You might read this excellent article: Intro to COM[^]
The COM class clsid is defined in a header somewhere, what kind of object is it?
Michael Dunn's second part to that Introduction to COM series explains it all quite clearly:
Behind The Scenes of the COM Server[^]
"A key with the server's GUID as its name must be created under the HKEY_CLASSES_ROOT\CLSID key, and that key must contain a couple of values listing the server's location and its threading model. The DllGetClassObject() function is called by the COM library as part of the work done by the CoCreateInstance() API."
|
|
|
|
|
Thanks for your reply, actually I want to read the content of .doc file. I do not know how to do that, if you have some idea about it please tell me how to do that?
I also searched on google but could not get much help, I just came to know that COleStreamFile class might be usefull but how to do that with this class I don't know?
|
|
|
|
|
Hi I am new to COM. I am working on a java application that will make use of COM to get the required interface Information from I2 Analyst Note Book V6. And the application is working fine. Recently we upgraded the I2 V6 to V7 and Modified the Interface as mentioned in I2 V7 support docs. After the upgradtion we are getting problems from COM.
The problem is in IDispatch::GetTypeInfo.Here the function returns S_OK but still the pointer to ITypeInfo is null. In which scenario this will happen. Following is the code snippet which does this.
=================Code Snippet==============
ITypeInfo* pTypeInfo;
UINT pctInfo;
m_hRet = m_pDisp->GetTypeInfoCount(&pctInfo);
if(m_hRet!=S_OK || pctInfo != 1)
{
return false;
}
m_hRet = m_pDisp->GetTypeInfo(0,LOCALE_SYSTEM_DEFAULT,&pTypeInfo);
if(m_hRet!=S_OK || pTypeInfo==NULL)
{
if(pTypeInfo==NULL && m_hRet==S_OK )
MessageBox(NULL, "Error : GetTypeInfo, pTypeInfo is null", "1", MB_OK);
return false;
}
===========================================
After upgrading to I2 V6 to I2 V7. I am getting the error 'Error : GetTypeInfo, pTypeInfo is null' in the MessageBox.
Please help me ,since i am totally stuck at this point.thanks in advance
|
|
|
|
|
Try to modify second parameter of m_pDisp->GetTypeInfo(...) from LOCALE_SYSTEM_DEFAULT to LOCALE_USER_DEFAULT or to 0 at all.
With best wishes,
Vita
|
|
|
|
|
I tried both(LOCAL_USER_DEFAULT ad 0 ).But still i am getting the same error...
|
|
|
|
|
Hello Everybody,
I have basic query regarding ClassFactory.
As we know ClassFactory creates the components.
Clients call CoGetClassObject which calls DllGetClassObject,
which creates ClassFactory and returns an IclassFactory pointer,
Now my doubt is what if DllgetClassObject creates the component directly,
and return the required interface from the component.
Why we need to have a classfactory, why can't we directly create the compnent in DllGetClassObject.
Waiting for your response.
Thanks,
Shyam
|
|
|
|
|
Hi all,
I want to call an exe from my .net application using form's Showdialog() method.The control is moving to the caller successfully. but while closing that application i want to get the the result of database operation [The Result is like 1 for success and any other string for failure].
How can i achieve?
thanks in advance
Sri
|
|
|
|
|
I have developed COM add-in for microsoft word.I am handling events of microsoft word like DocumentOpen, DocumentBeforeSave. In Open / save events, I am getting the content of an active document. But I am getting only text or only image or only tables at a time.
How to retrieve byte array pointer to the word document entire content irrespective of data type (image, string, and table).
Vijit P
|
|
|
|
|
Greetings!
What i am trying to do is to access the IDropTarget interface of another process. I have dug into this and have found out -and of course, correct me at any time if i am wrong- that marshaling seems to be the way to go. So my question is basicly: how?
I think i need to create or somehow obtain a proxy object for the interface and use that to marshal calls to the original IDropTarget. I used the OLE/COM Object Viewer (that comes with Visual Studio) to look at IDropTarget and checked out its "ProxyStubClsid32" which seems to be "PSFactoryBuffer", so i looked up the IPSFactoryBuffer interface. Now at this point what confused me is that under IDropTarget it says that the ClassID of the factory is "0x00000320, 0x0000, 0x0000, 0xC0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x46" while IPSFactoryBuffer seems to have "0xD5F569D0, 0x593B, 0x101A, 0xB5, 0x69, 0x08, 0x00, 0x2B, 0x2D, 0xBF, 0x7A", aren't these ClassIDs refering to the same thing?
Anyways, what i am guessing now is that i need to create/obtain an IPSFactoryBuffer, use its CreateProxy to create a proxy interface, connect that somehow to the IDropTarget sitting in the other process and issue calls to the proxy. But if i try to create an IPSFactoryBuffer with CoCreateInstance i get the error "Class not registered", i also tried to use CoGetClassObject with the same result. And even if i had a factory, how do i create a proxy object connected to the original IDropTarget? About the original droptarget i have the following information: it's address and the handle of a marshaling window which is -most likely- created by the RegisterDragDrop call.
Am i completely off the right path? COM is sometimes a bit confusing to me. Thanks in advance for any hints or kicks which could get me ahead.
|
|
|
|
|
Hi there,
I have a strange error message that I would like to submit to you hoping you can help.
I have an MFC C++ application which communicates with a second MFC application through OLE Automation. This second application has a loop which constantly communicates with a hardware device through the serial port of the computer and updates some of its member variables reflecting the state of the hardware. The main application has a timer that periodically checks the values of the variables of the second application through OLE Automation.
My problem is that every now and then, apparently in a random fashion, I get the following error message "Overlapped I/O operation is in progress". If I close this message, it comes back up again almost immediately.
This is a rather generic message but I suspect it has something to do with my OLE communication. Does anyone have an idea? When that error occurs, the second application is still running fine and communicating fine with the hardware so I guess the serial communication is not the origin of the problem.
Could it be an issue linked to the lifetime of the handle on the OLE object?
In case that helps, here is how I start the second application from within the first one through OLE:
int CRXGemApp::StartRemoteApplication(void)
{
if(m_RemoteApp != NULL)
return 0;
if(m_RemoteApp == NULL)
{
m_RemoteApp = new CRXMFX();
COleException e;
if(!m_RemoteApp->CreateDispatch("REMOTEAPP.Application", &e))
{
AddToErrorLog("could not startthe Application");
delete m_RemoteApp;
m_RemoteApp = NULL;
return -1;
}
DISPID dispID;
BYTE *parmStr;
CString cx = "visible";
BSTR szMember = cx.AllocSysString();
m_RemoteApp->m_lpDispatch->GetIDsOfNames( IID_NULL, &szMember, 1, LOCALE_USER_DEFAULT, &dispID );
::SysFreeString(szMember);
parmStr = (BYTE *)( VTS_VARIANT );
}
int Timeout = 5;
int IncTime = 1000;
CChrono Chrono;
Chrono.InitChrono();
Chrono.StartChrono();
double t = 0.0f;
while(m_RemoteApp->GetStatus() < 0 && t < Timeout)
{
Chrono.DureeChrono(t);
}
if (m_RemoteApp->GetStatus() < 0)
{
StopRemoteApplication();
AddToErrorLog("Communication error with the hardware.");
return -2;
}
return 1;
}
|
|
|
|
|
|
Shucks, this is a bit difficult to explain, but hopefully someone will understand.
I am developing an application that reads data from a serial port. The device that connects to the port is not available yet - fortunately I know the data stream format. I want to develop the application using a "virtual" COM port, meaning I'll have another application producing a data stream to the COM port in use by the application in development.
To perhaps explain it better, I want to develop two apps, one that produces a data stream to "COM1" and the real application to read from this COM1 port. After testing with various values from the "COM" port, I want to distribute this app without further development and must be able to read from a real COM port.
Please point me in the right direction.
Thanks
the confused are confused beyond confusion
|
|
|
|
|
A little off topic to begin with, but this board is designated to contain questions about COM where the abbreviation stands for the "Component Object Model" and not the serial communications port.
Just in case you had them mixed up.
Now to a suggestion for your question:
Develop a simulator for your device, but instead of a serial port you can use named pipes. Create the named pipe in your simulator with ::CreateNamedPipe() and then open it with ::CreateFile() in your application that is supposed to communicate with your future device.
You will be able to use the same API as when using a real serial port, but calls to ::SetCommState() and such will return FALSE . You will, however, be able to build the complete communication logic and the protocol and leave it unchanged when you open the real serial port instead of a named pipe.
I've used this technique several times in situations very similar to yours, which made it possible for me to develop client applications without the hardware.
"It's supposed to be hard, otherwise anybody could do it!" - selfquote "High speed never compensates for wrong direction!" - unknown
|
|
|
|
|
Hi,
i had creted Outlook addin in VS-2008, its working fine in my machine but when i try to install it in client machine, its giving the following error
Location: C\Program Files\Common Files\Microsoft shared\VSTO\8.0
Load Behaviour: Not Loaded. A runtime error occured during the loading of the COM Add-in
what are the Prerequisites reqitred for creating Outlook Setup.
Can any one please help me for installing in the client machine.
regards,
valli
srivalli.krothapalli
|
|
|
|
|