|
Is the second application compiled with Unicode turned on? Because your passing an LPCTSTR (which can be ASCII or Unicode, depending on pre-processor macro settings) to GetActiveObject, where you are meant to pass an LPCWSTR
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
Sorry I am new to this, I searched for this option, i didn't find it?
Please tell me where I can find this option in Microsoft visual studio 2008(Professional edition).
Regards,
gtag
|
|
|
|
|
Don't worry too much about that - just make sure you use
L"Excel.Application"
instead of
_T("Excel.Application")
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
I changed it , but same issue.
Is there any other way?
Regards,
Gtag
|
|
|
|
|
What HRESULT was returned from GetActiveObject?
Was Excel running when you did the GetActiveObject call?
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
hr = 0x800401e3 Operation unavailable
Excel was running.
With other application I can attach with both option s _T or L.
Even can read xlworksheet names and all.
Regards,
Gtag
|
|
|
|
|
gtag wrote: hr = 0x800401e3 Operation unavailable
Right - well that explains why you weren't getting a pointer to the Excel application. Doing a quick Google (you know, like you could have done) brings up this MS support page[^] which deals with your scenario.
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
Surely I will check out the blog u mentioned.
After doing little analysis on both the applications I have got few inputs for not getting attached to active object, but solution I couldn't?
Following are the functions called from comip.h
HRESULT GetActiveObject(const CLSID& rclsid) throw()
{
_Release();
IUnknown* pIUnknown;
HRESULT hr = ::GetActiveObject(rclsid, NULL, &pIUnknown);
if (SUCCEEDED(hr)) {
hr = pIUnknown->QueryInterface(GetIID(), reinterpret_cast<void**>(&m_pInterface));
pIUnknown->Release();
}
if (FAILED(hr)) {
// just in case refcount = 0 and dtor gets called
m_pInterface = NULL;
}
return hr;
}
// Attach to the active object specified by clsidString.
// First convert the LPCWSTR to a CLSID.
//
HRESULT GetActiveObject(LPCWSTR clsidString) throw()
{
if (clsidString == NULL) {
return E_INVALIDARG;
}
CLSID clsid;
HRESULT hr;
if (clsidString[0] == '{') {
hr = CLSIDFromString(const_cast<LPWSTR> (clsidString), &clsid);
}
else {
hr = CLSIDFromProgID(const_cast<LPWSTR> (clsidString), &clsid);
}
if (FAILED(hr)) {
return hr;
}
return GetActiveObject(clsid);
}
Of these functions one func is having "_Release();" . This is not getting called in one of my application and error is which i mentioned in previous post.
I wonder that same code works perfectly in one application on same pc and in other it's not.
Anyway I will check the workaround thing which u mentioned.
Thank you
Regards,
Gtag.
|
|
|
|
|
Read the page I pointed you at. Don't bother digging through the Microsoft library code - the error is not in that.
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
NO, I am getting same error value in hr.
I am still trying.
As I am mentioned in above , "_Release();" is not getting called.
I checked in other app where it is working if I right click on _Release() and see the definition , nothing is reflecting overthere but when I did the same thing in current app(where its not working) , symbols are not loaded it is showing.
Is this the issue?
Regards,
Gtag
|
|
|
|
|
|
Hi Stuart,
Thanks for helping me in this issue.
Today I resolved the issue.
It has to do with security, as my application is having service which runs under "System" user name and Excel runs under other login not system, so it was not accessing excel under other login.
Now I am able to access active object.
Thanks once again.
|
|
|
|
|
Here is my C# file.
using System;
using System.Collections.Generic;
using System.Text;
using System.Net;
using System.IO;
using System.Runtime.InteropServices;
namespace AdobeDSL
{
public class DSL
{
public DSL()
{
}
public string GetID(string username)
{
}
public string Verify(string ID)
{
}
}
}
Then I have this C++ file.
#import "Path\AdobeDSL.tlb" named_guids raw_interfaces_only
#include <iostream>
#include <string>
using namespace std;
int main()
{
CoInitialize(NULL);
AdobeDSL::_DSLPtr DSLTest;
HRESULT Result1 = DSLTest.CreateInstance(AdobeDSL::CLSID_DSL);
if (Result1 == S_OK)
{
cout << "Worked!" << endl;
}
CoUninitialize ();
cin.get();
return 0;
}
This all works just fine. But I should be able to call DSLTest->GetID("value");
GetID and Verify do not show up in the members list. What do I have to do to get them to show up.
|
|
|
|
|
Did you try calling them?
It could be an intellisense problem.
«_Superman_»
I love work. It gives me something to do between weekends.
|
|
|
|
|
I wish it was that easy. If I try to call the functions, I get an error saying the member does not exsist.
|
|
|
|
|
I hope you have already got it working by now. If not, Check this and this.
I dont get to work much in managed environment but I remember using some google's managed dll in my unmanaged application arnd a year ago.
|
|
|
|
|
Yes, I actually did get it working! CP had another link that was pretty much like the first link you posted! So I finally got it working! Thank you for the help, and the links!
|
|
|
|
|
Hi ,
I have modified a method of a com interface. from
virtual /* [helpstring][id] */ HRESULT STDMETHODCALLTYPE Restore(
/* [in] */ BSTR bszServerInstanceName,
/* [in] */ unsigned int uiNumCnt,
/* [in] */ BSTR *lpbszDb,
/* [in] */ BSTR *lpbszNewDs,
/* [in] */ BSTR bszDocumentXML,
/* [in] */ BSTR bszWriterXML,
unsigned int uiarg,
BSTR *lpbszList,
BSTR *lpbszTarget,
/* [in] */ BOOL boolflag,
/* [in] */ BSTR bszType) = 0;
to
virtual /* [helpstring][id] */ HRESULT STDMETHODCALLTYPE Restore(
/* [in] */ BSTR bszServerInstanceName,
/* [in] */ unsigned int uiNumCnt,
/* [in] */ BSTR *lpbszDb,
/* [in] */ BSTR *lpbszNewDs,
/* [in] */ BSTR bszDocumentXML,
/* [in] */ BSTR bszWriterXML,
unsigned int uiarg,
BSTR *lpbszList,
BSTR *lpbszTarget,
/* [in] */ BOOL boolflag,
/* [in] */ BSTR bszType,
/* [in] */ BOOL boolLRflag) = 0;
I have added a bool to the end of parameter list.
when I call this method from my C code the last BOOL data I get is garbage whats wrong?
Best wishes
|
|
|
|
|
shivako wrote: I have modified a method of a com interface
You should never, ever do that without up-versioning the interface. I suspect the COM server you're talking to is one that conforms to the original interface and doesn't realise there's another BOOL going in.
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
Make sure that you have- updated the IDL-file
- rebuilt the typelibrary without warnings and/or errors
- rebuilt the server without warnings and/or errors
- re-imported the typelib in the client (the *.tli and *.tlh files should be updated)
- that the parameter list of the function has changed in the client code
- rebuilt the client without warnings and/or errors
BTW, I really hope this server and its interface haven't been distributed yet.
If they are, you're breaking one important rule of COM.
"It's supposed to be hard, otherwise anybody could do it!" - selfquote "High speed never compensates for wrong direction!" - unknown
|
|
|
|
|
shivako wrote: I have modified a method of a com interface
That's GAME OVER .
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
I am using following dll's in VC++
mso.dll
vbe6ext.olb
namespace Office
comutil
I am getting following build errors:
Error 96 error LNK2005: "void __stdcall _set_com_error_handler(void (__stdcall*)(long,struct IErrorInfo *))" (?_set_com_error_handler@@YGXP6GXJPAUIErrorInfo@@@Z@Z) already defined in comsupp.lib(comsupp.obj) comsuppwd.lib
Error 97 error LNK2005: "void __stdcall _com_issue_error(long)" (?_com_issue_error@@YGXJ@Z) already defined in comsupp.lib(comsupp.obj) comsuppwd.lib
Error 98 error LNK2005: "void __stdcall _com_issue_errorex(long,struct IUnknown *,struct _GUID const &)" (?_com_issue_errorex@@YGXJPAUIUnknown@@ABU_GUID@@@Z) already defined in comsupp.lib(comsupp.obj) comsuppwd.lib
Error 99 error LNK2005: "long __stdcall _com_dispatch_propget(struct IDispatch *,long,unsigned short,void *)" (?_com_dispatch_propget@@YGJPAUIDispatch@@JGPAX@Z) already defined in comsupp.lib(comsupp.obj) comsuppwd.lib
Error 100 error LNK2005: "long __cdecl _com_dispatch_propput(struct IDispatch *,long,unsigned short,...)" (?_com_dispatch_propput@@YAJPAUIDispatch@@JGZZ) already defined in comsupp.lib(comsupp.obj) comsuppwd.lib
Error 101 error LNK2005: "void (__stdcall* __errorPfn)(long,struct IErrorInfo *)" (?__errorPfn@@3P6GXJPAUIErrorInfo@@@ZA) already defined in comsupp.lib(comsupp.obj) comsuppwd.lib
Error 102 error LNK2005: "long __stdcall _com_dispatch_raw_propget(struct IDispatch *,long,unsigned short,void *)" (?_com_dispatch_raw_propget@@YGJPAUIDispatch@@JGPAX@Z) already defined in comsupp.lib(invkprxy.obj) comsuppwd.lib
Error 103 error LNK2005: "long __cdecl _com_dispatch_raw_propput(struct IDispatch *,long,unsigned short,...)" (?_com_dispatch_raw_propput@@YAJPAUIDispatch@@JGZZ) already defined in comsupp.lib(invkprxy.obj) comsuppwd.lib
Error 104 fatal error LNK1169: one or more multiply defined symbols found
Please give me clue to solve this issue.
I am new to VC++ stuff.
Thanks in advance.
Regards,
Gtag
|
|
|
|
|
Well, you're including multiple versions of the COM support library - I see comsupp.lib and comsuppwd.lib for a start.
You need to examine your project settings to see where the libraries are being pulled into your project.
I presume you're using #import to interface to mso.dll and vbe6ext.olb?
How are you 'using' comutil, by the way?
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
#import \
"C:\Program Files (x86)\Common Files\Microsoft Shared\OFFICE12\mso.dll"\
rename("DocumentProperties", "DocumentPropertiesXL"),\
rename("RGB", "RBGXL")
//Microsoft VBA Objects
#import \
"C:\Program Files (x86)\Common Files\Microsoft Shared\VBA\VBA6\vbe6ext.olb"raw_interfaces_only,\
rename("Reference","ignorethis"),rename("VBE","XLVBE")
//Excel Application Objects
#import "C:\Program Files (x86)\Microsoft Office\Office12\EXCEL.EXE"\
rename("DialogBox", "DialogBoxXL"),rename("RGB", "RBGXL"),\
rename("DocumentProperties", "DocumentPropertiesXL"),\
rename("ReplaceText", "ReplaceTextXL"),\
rename("FindText", "FindTextXL"),\
rename("CopyFile", "CopyFileXL"),\
rename("VBE","XLVBE"),\
exclude("IFont", "IPicture") no_dual_interfaces
In property pages->linker->input -->additional dependencies i mentioned comsuppw.lib and comsupp.lib.
Please tell me what and all I need to check in project settings.
#include "comutil.h"
#pragma comment(lib, "comsuppw.lib")
|
|
|
|
|
Your #imports are fine.
I've just looked at a project of mine that #imports Excel and I don't #include comutil.h and I don't mention comsupp or comsuppw at all.
In fact, after some investigation, I can say that you don't need to mention them at all. The .tlh file created by the #import includes comdef.h, which in turn a) #includes comutil.h and b) uses #pragma comment to reference the correct comsuppxx library.
So to fix your issue, get rid of your #pragma comments and get rid of references to comsuppxx libraries in your linker input properties.
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|