|
|
Current clients of the your COM component rely on its interface as it stands. If you change the interface, i.e. the (binary) contract between the COM server and its clients, then you probably break the client themselves.
Interfaces must be immutable is one of the fundamental principles of COM .
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
|
|
|
|
|
hi all
I am working with an application in which i required to send fax periodically . For that i used windows service. If i started the service for first time the pdf document was sent successfully thru fax( i used faxcom.dll for this purpose). But second time on words it is not at all sending the fax. The application was executed and stopped at faxserv.Send() method.I was given timer delay 2 minutes in service to execute code to send fax. I just restarted my system then the system was showing an error like ' The adobe reader was encounterd a problem ' . After i checked the application(service) it was working properly. (it seems the system it self rectified the error in adobe)
But why the adobe was encoutered the problem (i can say that the problem for adobe is with my service only).
plz let me share any information in this regard .
Thanks in advance
Pinky
|
|
|
|
|
Hi there
I'm desperately searching for example code helping me to write a Rose Add-in in Vc++. There are couple of VB6 examples out there, but none in C++. I have knowledge in COM, and there is a TLB of Rational Rose available, but I'm stuck.
HELP !!!
|
|
|
|
|
I have a thread function which is something like this.
1)
Extract the pointer value which comes as part of the thread function call.
2)
Initialize the thread with ::CoInitializeEx(0,COINIT_MULTITHREADED) so that it enters the MTA of the process.
3)
Use the pointer extracted above in Step 2 to make a COM call.
The actual COM call (step 3) is made after the thread is initialized for using COM (step 2).
Is this fine? Should I also change my thread function such step 2 preceeds step 1.
Thanks
Rajdeep
|
|
|
|
|
The pointer you are passing needs to be marshaled because the coclass it belongs to is created within other appartment (unless your object is created withing MTA)
Sohail
modified 21-Apr-21 21:01pm.
|
|
|
|
|
Hi,
I have the the following body of code:
STDMETHODIMP_(ULONG) CoCarClassFactory::Release()<br />
{<br />
if(--m_refCount == 0)<br />
{<br />
delete this;<br />
return 0;<br />
}<br />
<br />
return m_refCount;<br />
}
My question is about the return 0; statement after the delete this; line. How can the function still return after deleting the object that contains itself?
TIA!
I am a SysAdmin, I battle my own daemons.
|
|
|
|
|
DenClancy wrote: My question is about the return 0; statement after the delete this; line. How can the function still return after deleting the object that contains itself?
just check this out, try it on any compiler :-
class ABC
{
public:
void MyFunc() { cout<<"hello atl";}
};
void main()
{
ABC *c= NULL;
c->MyFunc();
}
are you wondering it will work or not.. but it will work.. try it!
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow Never mind - my own stupidity is the source of every "problem" - Mixture
cheers,
Alok Gupta
VC Forum Q&A :- I/ IV
Support CRY- Child Relief and You/codeProject$$>
|
|
|
|
|
|
In addition to the previous posts. The reason why this works is that it is ok to execute code after the class object is deleted only if you do not try to use any non static class variables.
John
|
|
|
|
|
Hi all,
I am working on an application that is written in Java. It's basically a middleware server. The client is a Java application. However, there's a need to develop an Excel client. I have been provided with an addin that has certain functions that the VBA can call. The other side of the COM DLL is made of c++ programs that use JNI to pass data to Java and receive results. I have successfully created new functions to work on this.
When I started working on this I created a '|' delimited string to pass data from Excel to COM to Java and vice versa. The strings looked like this:
|Property1=Value1|Property2=Vaue2|........|PropertN=ValueN|
In the early stages these functions that I had created were simple atomic functions i.e. take in one string spit out resultant string. Now, however I need to be able to send arrays of such strings and also receive results in the form of arrays of strings.
I used CComSafeArray to do so.
Here's the code of what I did
STDMETHODIMP CAddin::MyClass_LoadVals(VARIANT ValIds, VARIANT* outVals)<br />
{<br />
<br />
USES_CONVERSION;<br />
std::list<std::string> result;<br />
std::list<std::string> inpArr;<br />
<br />
CComVariant var;<br />
<br />
CComSafeArray<bstr> parr;<br />
CComBSTR* bstrs;<br />
var.Attach(&valIds);<br />
parr.Attach(var.parray);<br />
<br />
int dim = parr.m_psa->cDims;<br />
if (parr.m_psa->cDims != 1)<br />
return S_FALSE;<br />
<br />
if(parr.m_psa->rgsabound->cElements > 1)<br />
{<br />
SafeArrayAccessData(parr,reinterpret_cast<void **="">(&bstrs));<br />
for (int i=0;i < parr.m_psa->rgsabound->cElements;i++)<br />
{<br />
std::string tmp;<br />
tmp = W2CA(bstrs[i]);<br />
inpArr.push_back(tmp);<br />
}<br />
}<br />
SafeArrayUnaccessData(parr.m_psa);<br />
<br />
VariantInit(outVals);<br />
<br />
if(JavaInterface::JavaInterface_LoadVals(inpArr,result)){<br />
outVals->vt=VT_ARRAY|VT_BSTR;<br />
createStringArrayVariant(outVals,result);<br />
return S_OK;<br />
}else{<br />
getCalypsoError();<br />
}<br />
<br />
return S_OK;<br />
}</void></bstr></std::string></std::string>
Code for createStringArrayVariant(VARIANT,std::list<std::string> :-
<br />
bool createStringArrayVariant(VARIANT* to, std::list<std::string>& from)<br />
{<br />
VariantInit(to);<br />
SAFEARRAYBOUND bound = {from.size(), 0};<br />
SAFEARRAY* array = ::SafeArrayCreate(VT_VARIANT, 1, &bound);<br />
<br />
long index = 0;<br />
VARIANT v; VariantInit(&v);<br />
for(std::list<std::string>::iterator i = from.begin(); i != from.end(); i++)<br />
{<br />
convertStringToVariant(&v, *i);<br />
::SafeArrayPutElement(array, &index, (void*)&v); ++index;<br />
}<br />
to->vt = VT_VARIANT | VT_ARRAY;<br />
to->parray = array;<br />
return true;<br />
}</std::string></std::string>
Please bear in mind that createStringArrayVariant(...) function was provided to me with the product that I am working on.
The resultant output is correctly passed to Excel. I load it as a variant array and try and do further processing. However, the problem is when the output is loaded, Excel starts crashing while doing simple things like updating values in the cells or running a simple loop. These parts of VBA code work fine in isolation i.e. without loading that array of values. Sometimes when Excel crashes, it just simply disappears without so much as an error report. My logs for the addin and the logs for Java, none of them indcate anything. Is the array too big or is this sort of programming not advisable for linking VBA and C++. I really need this to work. Any help would really be appreciated.
Please bear in mind that I have little experience with C++ and almost no exprience with Visual C++, prior to working on this project. Whatever I have learnt is from the existing code or Google, so I could be quite wrong with my code here.
I'd appreciate any leads in this matter.
Thanks for your help
Sukant Saddi
|
|
|
|
|
Hi Sukant,
Looking at your code, I would say that createStringArrayVariant should change a little.
Create your safe array as ::SafeArrayCreate(VT_BSTR, 1, &bound); .
I am saying this because your MyClass_LoadVals seems to expect that. Also, it is much easier to use:
CComBSTR str = parr.GetAt(index);
than your call to SafeArrayAccessData
Anyway, my guess is your data has been destroyed. CComVariant var; is not really necessary, use parr.Attach(ValIds.parray);
You should detach it as well.
God bless,
Ernest Laurentin
|
|
|
|
|
Hi all,
I wrote a DLL in C#, and exposed some functions to COM interop by following these guidelines:
-declare a custom constructor
-declare the functions to be exposed as public.
-declare an interface that the class implements.
-created a type library (.tlb) using regasm.
Now the DLL functions can be viewed and accessed from an unmanaged language such as VB6 (tested it and it works).
The problem is that another C++ developer wants to use this DLL on another machine to create an application that would be distributed to clients.
What should steps should be done so the developer could successfully use this DLL in his code as well as the end users who will deploy and use the application?
Thank you for your help.
|
|
|
|
|
|
Hi
I’m facing one major issues mentioned below in my HostEmulatorClient application which is using "Attachmate EXTRA! X-treme 9.0" COM component.
- I created a windows form to connect with ORBIT system using EXTRA component. It is
working fine. I can open & view PTs with Phase status as “Await”. Now I have converted this
form into a window service as being a project requirement but my window service is not able to
connect with ORBIT system using the EXTRA component. My Window Service is updating a local log
file. Even in this log file there is no error/exception logged. I’m not able to trace the issue
here.
From code level I do not see any problem. These problems may be because of some missed configuration which I’m not aware about. Below is the code where I try to connect
with ORBIT system.
public bool Open()
{
try
{
EXTRA._System sys = new EXTRA.ExtraSystemClass();
EXTRA.Sessions sss = new EXTRA.ExtraSessionsClass();
EXTRA._Session ses;
EXTRA.Screen scr;
string str = sys.DefaultFilePath;
LogHelper.WriteLog("Path : " + str + "\\" + _AccessDetail.EmulatorFileName + ".EDP", LoggingCategory.AllLoggingMessgesLog);
//LOG IS GENERATED ONLY TILL THIS LEVEL. THERE IS NO LOG FOR LATER LOG STATEMENTS, LIKE LOG FOR EXCEPTION OCCURRED ETC
ses = (EXTRA.ExtraSession)sss.Open(str + "\\" + _AccessDetail.EmulatorFileName + ".EDP");
scr = (EXTRA.ExtraScreen)ses.Screen;
LogHelper.WriteLog("Session instance created ", LoggingCategory.AllLoggingMessgesLog);
return true;
}
catch (Exception ex)
{
LogHelper.WriteLog("Exception occured : " + ex.ToString(), LoggingCategory.AllLoggingMessgesLog);
throw ex;
}
}
Please if anyone around there has faced such issue & has got the solution or at least the cause for
this issue please share it.
Thanks
Kamal Chauhan
|
|
|
|
|
is it a permissions issue ? - most services by default run in the LocalSystem account - this has no access to Network functions
'g'
|
|
|
|
|
My service, called HostEmulatorService is running under the following account:
NT AUTHORITY\LocalService
If this is the possible cause for the issue I'm facing, please suggest the way out.
Thanks
Kamal Chauhan
|
|
|
|
|
I'm writing my first shell extension dll, and I'm trying to figure out how to pass the Recycle bin files/folders anme CShellExt::InvokeCommand at right click of menu item. I am getting others files and folders name.
Some sennipt is attached.
<br />
void CCoMenHandler::GetSelectedFiles(LPCITEMIDLIST pidlFolder,IDataObject *pdtobj)<br />
{<br />
g_szSelectedFiles.RemoveAll();<br />
<br />
if (pdtobj) <br />
{<br />
pdtobj->AddRef();<br />
<br />
STGMEDIUM medium;<br />
FORMATETC fe = { CF_HDROP, NULL, DVASPECT_CONTENT, -1, TYMED_HGLOBAL};<br />
<br />
<br />
HRESULT hr = pdtobj->GetData (&fe, &medium);<br />
if (FAILED (hr))<br />
{<br />
return ;<br />
}<br />
<br />
char path[MAX_PATH];<br />
<br />
UINT fileCount = DragQueryFile((HDROP)medium.hGlobal, 0xFFFFFFFF,<br />
path, MAX_PATH);<br />
<br />
if (fileCount>0)<br />
{<br />
g_szSelectedFiles.SetSize(fileCount);<br />
<br />
for (UINT i=0;i<fileCount;i++) <br />
{<br />
memset(path, 0, MAX_PATH);<br />
if (DragQueryFile((HDROP)medium.hGlobal, i, path, MAX_PATH)) <br />
{<br />
g_szSelectedFiles.SetAt(i, path);<br />
}<br />
}<br />
<br />
g_szSelectedFiles.FreeExtra();<br />
}<br />
<br />
ReleaseStgMedium(&medium);<br />
}<br />
<br />
<br />
}<br />
Thanx in advance.:
|
|
|
|
|
Hi I have a RTD Server that work with the application EXCEL.
I retrieve the information with cell function like this:
=RTD("progID","", "topic1", "topic2","topic3","topic4","topic5")
With some research on Google. I try to retrieve the data programmatically
Excel.Application excel = new Excel.ApplicationClass();
excel .WorksheetFunction.RTD("progID", "", "topic1", "topic2", "topic3", "topic4", "topic5");
and I have this error at compilation
No overload for method 'RTD' takes '7' arguments
Did anyone know how to retrieve data programmatically from rtd server with callback function
Thank you
Bang
|
|
|
|
|
Hi,
I have a COM dll, in which there are many interaces/objects. Threre is a one object which all other objects are retrieved.
It means I need one CoCreateInstance() to initialize top level of object(TopObject).
Other object are initialize like :
Otherbject1=TopObject->Store;
Otherbject2=TopObject->Add->File;
Is this Correct?
TopObject->Release();
Otherbject1->Release();
Otherbject2->Release();
If not then which objects I have to release?
|
|
|
|
|
pther wrote: Is this Correct?
Yes, the tricky handling of interface reference count for such objects must be handled by the COM server (i.e. your TopObject).
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
|
|
|
|
|
Consider an MFC Activex control, Example, Vehicle,
Following are the interfaces,
_DVehicle , _DVehicleEvents - Default interfaces.
ICar - Custom interfaces.
The default interface (_DVehicle) returns pointer to ICar interface for accessing the ICar methods/properties.
1. Now , I need to add new methods/properties/Events to the above
interfaces. Since modifying the existing interfaces is against the rules,
How do I go about it?
2. If I write a new interface ICar2, then what will happen to the old
applications that are using old interface ICar ? How will the default (_DVehicle) interface decide which interface pointer it should return?
3. How do I add a new Event Interface?
4. What is the purpose of changing type library version. If I add a new
interface then do I have to change the major version of the type library (Ex:
1.0 - 2.0) ?
|
|
|
|
|
Sir,
My COM class not getting registered.
Iam trying to register the COM DLL with .regsvr32.
It is not displaying either Dll Registered or Failed messge.
So, when i try to create instance of thet class, using CoCreateInstance
it returned Failure Code -2147221164 , that means Class not registered.
I want to know the reasons of CoCreateInstance failure.
Help me Plz.
Krishna.
|
|
|
|
|
Are you using /s ?
Usage: regsvr32 [/u] [/s] [/n] [/i[:cmdline]] dllname
/u - Unregister server
/s - Silent; display no message boxes
/i - Call DllInstall passing it an optional [cmdline]; when used with /u calls dll uninstall
/n - do not call DllRegisterServer; this option must be used with /i
---------------------------
OK
---------------------------
Following might help for error messages
http://support.microsoft.com/kb/249873[^]
Sohail
modified 21-Apr-21 21:01pm.
|
|
|
|
|
Iam able to register my DLL After small modification in project settings.
I removed _WinmainCrtstartup in Entry point symbol tab.
|
|
|
|