|
Make sure that it is an exe service rather than a dll service. A dll singleton loads a different instance per app. An exe will have only one instance.
ed
The nice thing about egotists is that they don't talk about other people.
Lucille Harper
|
|
|
|
|
Ok. I'm trying to use a COM OCX object in a C program. I've done some research and found out how to call and instantiate a COM object from C. However, I do not know how to generate a header file for object type or interface declarations.
SOPTEST replied with some useful info but all I can find out is info on how to develop a COM object using C and not how to use an existing one that is already in the registry that I didn't develop. I want to use MSCOMM32.OCX in a C program. How do I get the declaration for the IMSComm and other interfaces?
I know how to get the IUknown interface, call QueryInterface, etc. And, I know that getting an interface pointer is really a void** so I could create a void pointer and call it anything I like and use it but that doesn't seem right or is it???? I've learned how to view the typelib, CLASSID, etc. from OLE/COM Object viewer so I don't think I'm an idiot, I just need some help.
Is there someway of interpreting the type library and converting it into a header file that I am not aware of? Anybody??
|
|
|
|
|
Use "oleview" to open type library. From "File" menu you can "Save as" *.IDL, *.H or *.C file. If you save it as *.IDL file then compile it with MIDL compiler to generate proxy/stub files.
soptest
|
|
|
|
|
I used "oleview". I did not know you could save .c or .h files from there but when I tried, it didn't work. Apparently, it uses a console window but the error happens so fast and the console window closes before I can see it. However, I was able to save the .idl file. But, going from using VC++ before with Add To Project | Components and Controls that generates all C++ wrapper classes and as you say proxy/stub files for out of process.
|
|
|
|
|
I think I got it now. I was finally able to save a .c and .h files to the default directory (system32). I still got warnings or errors but I couldn't tell what they were. Looking at the contents it has the proper extern "C" declarations Cool!
Thanks again, SOPTEST
|
|
|
|
|
If you're using MSVC++ (and what else would you be using !!), you can use '#import ' to import COM objects. This will generate the required header files automatically when you compile the code. The one pain is that (with VC6, but not VC.NET, IIRC) you need to enter an absolute path to the DLL or OCX or whatever. (I've just looked it up - VC++NET lets you use a progid to say what class you want). MSDN (the one you get with VC++) should hopefully have enough info to get you started.
Just one thing - by default, VC++ will generate wrappers for the COM class - this may not be what you want.
Stuart Dootson
'Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p'
|
|
|
|
|
Whoops - just read your message properly - you say you're using C, as opposed to C++, so this may have been of no use whatsoever
Stuart Dootson
'Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p'
|
|
|
|
|
OK - not really a problem, but is there anything supremely wrong with this:
I've got some COM objects I'm using as helpers to get a scripting application (using IActiveScript with a user-selectable script engine) working (specifically, I've got an IActiveScriptSite implementation and some IDispatch-based objects that I'm inserting into the scripting namespace with IActiveScript::AddNamedItem). BUT...these objects are not registered COM classes, because they're just classes in a standard Win32 executable, not a COM server executable - I create them using 'new CComObject<class name> ' and manage them with _com_ptr_t..or is it CComPtr - can't remember which right now. It all seems to work - but is there any reason that I should be using properly registered servers & objects & things?
Stuart Dootson
'Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p'
|
|
|
|
|
Nope. If you're not going to use the objects outside the scope of your application, there's no reason to register them.
Scot Brennecke
Software Developer
VC++ MVP
|
|
|
|
|
I'm trying to utilize Microsoft's MS XML 4.0 parser to obtain some data from an XML file. I'm using C++ so im I'm having a bit of trouble writing a simple console app that can find an XML node of my choice and retrieve data associated with it. I am trying to utilize the XML DOM Method GetAttribute.
(as seen on MSDN @ http://msdn.microsoft.com/library/en-us/xmlsdk/htm/xml_mth_dg_5rfo.asp
I've worked through another example tutorial which creates a very simple app that loads the whole XML document and prints it to screen. I have no trouble with that but when I tried to utilize the MSDN example for GetAttribute, the code is riddled with problems and I have been unable to over come them. I'm sure if i saw a simple app that did what i was looking for i would understand how to use this better, but i have looked all over for such an animal and they are either way too big or way to simple to get anything from them. I am also having some troubles fully understanding _variant_t and _bstr_t.
If anyone can provide some advice or a very simple example (like something that can read 10 line xml file and find one tag in it and print its data), I would be grateful.
PS:
My problem may stem from: GetAttribute code: MSDN says it takes two parameters but it will not compile that way. SetAttribute appears to take similar parameters and it will compile with 2 parameters.
Thanks
Jeff Rothenberg
Project Engineer
Vector CANtech, Inc.
|
|
|
|
|
I've followed the tutorial about creating office addin's. The one I've created is an excel addin. It doesn't do anything, it's just a minimal addin.
But it doesn't show up in the excel addin-list, even though it's registered in windows registry.
The loadbehaviour should be set to 3 for automatic loading.
After compiling the project, using regedit shows 3 for loadbehaviour. So far so good.
But after running excel, eyeballing the addin is not there, the loadbehaviour in regedit changed to 2 ??????
What's going on here?
[VISUAL STUDIO 6.0] [MFC] [WIN98/2]
Bluute tette!
|
|
|
|
|
Hi,
as far as Excel addin is concerned, there are a few caveats as I have found out. If you have followed my tutorial and have a bare bones COM dll ready, to properly register it here's some info:
1) the registration key is to be created as usual at HKCU(or HKLM)->Software->Microsoft->Office->Excel->Addins->[Your Addins ProgID]. Now under this, apart from the usual FriendlyName,LoadBehavior and Description, you have to add 2 more entries. These are :
FileLocation - a string value of the physical path where the dll is located.
CommandLineSafe - a DWORD value(0 - unsafe 1-safe)
thus for my ATL Excel2000 addin project, the additions to the registry script(.rgs) are:
HKCU
{
Software
{
Microsoft
{
Office
{
Excel
{
Addins
{
'XLAddin.Addin'
{
val FriendlyName = s 'Excel2000 Addin'
val Description = s 'ATL COM Excel Addin'
val LoadBehavior = d '00000003'
val CommandLineSafe = d '00000001'
val FileLocation = s '%MODULE%'
}
}
}
}
}
}
}
with this, my addin gets loaded at startup.now as to the weird registry value changes, if the CommandLineSafe is 0,(i.e. addin is not safe to load) or the entry is missing ,Excel increments or decrements the LoadBehavior value, as some kind of a precaution.
happy addin programming.
'My capacity for happiness', he added, 'you could fit into a matchbox without taking out the matches first'.
- Marvin, the robot.
Amit Dey
sonork: 100:18407
msn: visualcdev
|
|
|
|
|
ok tnx
will try it...
[VISUAL STUDIO 6.0] [MFC] [WIN98/2]
Bluute tette!
|
|
|
|
|
do you know in a method call how to get the caller thread id if the interface has been marshalled ?
the problem is if the interface has been marshalled the GetCurrentThreadID return obvously the ID of the marshalled thread on which the interface has been marshalled. But how to get the thread id
of the calling thread ?
thanks in advance
|
|
|
|
|
why do you need to know it?
Len Holgate
www.jetbyte.com
The right code, right now.
|
|
|
|
|
Len,
it's funny you answer with a question
anyway it's a bit complicated to explain in few words.
I've used the IMessageFilter and it's not perfect but it works (only in STA)
ciao
|
|
|
|
|
Anonymous_com wrote:
it's funny you answer with a question
It's the only way to be sure that the person asking the question is asking the right question. There's no point in diving in to answer a question if you don't understand why the question is being asked and the context in which your answer will be used. This is especially true when the question is 'strange' ie something that you don't think the questioner should need to know. Often such a question arises from the fact that someone's already made a whole load of decisions to get to the point where they need to ask the 'strange' question. So by finding out why they need to ask the question you can often point out a more conventional way to solve the actual problem that they have and in doing so remove the need to answer the original question.
However, you don't give me any context, so I'll guess
You may be attempting to deal with reentrancy issues during COM method calls. I'd solve the problem differently
Len Holgate
www.jetbyte.com
The right code, right now.
|
|
|
|
|
Len,
nothing to do with reentrancy issues during COM method calls.
I've got an interface marshalled between different threads and
the interface under certain circumstancies need to know which thread has been calling
to provide different services because this thread is not so safe to produce
good result using this method. The problem of marshalling an interface is that
during the method call the GetCurrentThreadId obviously return the marhsalled thread id
ciao
|
|
|
|
|
Anonymous_com wrote:
I've got an interface marshalled between different threads and
I'd do it differently
Len Holgate
www.jetbyte.com
The right code, right now.
|
|
|
|
|
do I have to pray you to know how ?
|
|
|
|
|
Anonymous_com wrote:
do I have to pray you to know how ?
No, but I need a little more information. So back to my original question. Why do you need to know the thread id. Or, more precisely, why do you need to act differently depending on the caller's thread. I guess I'm asking what the 'certain circumstances' are and why the "thread is not so safe to produce good result".
Once I know this, I can answer
Len Holgate
www.jetbyte.com
The right code, right now.
|
|
|
|
|
Len,
you're tech teaser (no offense)
well, you can imagine this scenario as a super marshal :
certain threads cannot perform some operation
on certain methods. This could be achieved splitting the interface
but at the moment it's impossible
|
|
|
|
|
Anonymous_com wrote:
well, you can imagine this scenario as a super marshal :
certain threads cannot perform some operation
on certain methods. This could be achieved splitting the interface
but at the moment it's impossible
What I find difficult to reconcile is the fact that the knowledge of when the operation can safely be called by a particular thread is being placed in the object, rather than in the thread. If the thread deals with this issue then your problem goes away. The ideal solution is splitting the interface as you say. If that's not possible then personally I'd prefer to put the code that decides if the call is allowable or not on the caller's side of the interface rather than on the object's side. Doing it the way you're doing at the moment is likely to come back and bite you at a later date
Not amazingly helpful advice I know but I usually find it's worth dealing with the pain of these kinds of problems straight away - ie refactor the interface and adjust the design - rather than patching in a quick fix and finding myself with strangeness occurring just as I'm about to ship the product.
This code from Dharma Shukla's CoHack pages might help.
Len Holgate
www.jetbyte.com
The right code, right now.
|
|
|
|
|
Is there any way to kill a COM Object which I have started.
Normally I create the COM Object, and when I'm done with it I call obj->Release(); to decrease the ref. count.
But what if the COM Object stops responding?
Is there anyway to kill it...
Something like: KillComObjectNow(obj);
I know I know, it might cause resourse/memory leaks and stuff, but...
The problem is that I'm writing a server-thing for which people can write plug-ins/extensions in COM, and if one of those stops responding I want to kill it...
- Anders
Money talks, but all mine ever says is "Goodbye!"
|
|
|
|
|
You can use MessageFilters, look at IMessageFilter
|
|
|
|