|
From: Felix on 7 May 2008 14:35 Hello, i created my dialogbased application some month ago and now i am missing the feature "Automation", so that i can access some DLL-Functions via CreateInstance(..). If you create a new Project you are able to choose it in "advanced Features" in Visual Studio 2003. I did compare my project with a new one, which was created with automation. Everything seems to be ok now (after i did add some code), but if i use the same code in the app, which workes well usually, it crashes with a runtime error. I did compare the settings as well. Code: #import "c:\\program\\someguys.dll" no_namespace, raw_interfaces_only _hisdllfunc ptr; HRESULT hr = ptr.CreateInstance("{AD0B-AD5490...etc. etc.}"); ptr->dothething(&test); //this function call for the dll causes the crash... I hope you got any ideas on how to add automation to a project which was created without it... best regards, Felix
From: Joseph M. Newcomer on 7 May 2008 21:39 It is hard to tell from the code fragment you show, but did you check hr to see if the instance was properly created? If hr indicates an error, using ptr as shown would not work. Also, you declare _hisdllfunc ptr, you do ptr.CreateInstance, but then you do ptr->dothething. This should not even compile. Either ptr is an object, or it is a pointer to an object. The easiest way to add automation is what you did: create a new app, then carefully copy the automation-related code into your old project, or your old project code into the automation-enabled app. You did not say what you mean by "crash", which is essentially a meaningless term as you have used it. When this error occurs, something VERY SPECIFIC is displayed on your screen to indicate the problem, and you have not said what that is. If the code you showed is the code in its entirety, the obvious answer is, check hr first before trying to use ptr! joe On Wed, 7 May 2008 20:35:27 +0200, "Felix" <nmc-clan(a)gmx.de> wrote: >Hello, > >i created my dialogbased application some month ago and now i am missing >the feature "Automation", so that i can access some DLL-Functions via >CreateInstance(..). > >If you create a new Project you are able to choose it in "advanced Features" >in Visual Studio 2003. > >I did compare my project with a new one, which was created with automation. >Everything seems to be ok now (after i did add some code), but if i use the >same code in the app, >which workes well usually, it crashes with a runtime error. >I did compare the settings as well. > >Code: > >#import "c:\\program\\someguys.dll" no_namespace, raw_interfaces_only > >_hisdllfunc ptr; >HRESULT hr = ptr.CreateInstance("{AD0B-AD5490...etc. etc.}"); >ptr->dothething(&test); //this function call for the dll causes the crash... > >I hope you got any ideas on how to add automation to a project which was >created without it... > >best regards, >Felix > > > Joseph M. Newcomer [MVP] email: newcomer(a)flounder.com Web: http://www.flounder.com MVP Tips: http://www.flounder.com/mvp_tips.htm
From: Giovanni Dicanio on 8 May 2008 05:40 "Joseph M. Newcomer" <newcomer(a)flounder.com> ha scritto nel messaggio news:n8m424dh1b6qf4h2m9m78gdq7b8q97br4r(a)4ax.com... > Also, you declare _hisdllfunc ptr, you do ptr.CreateInstance, but then > you do > ptr->dothething. This should not even compile. Either ptr is an object, > or it is a > pointer to an object. Hi Joe, I think that OP's 'ptr' is a smart pointer. So it can have methods like CreateInstance, that are correctly called using dot notation. And the smart pointer overloads operator->, so the OP can call the original interface methods (like 'dothething') using operator->. It's similar to CComPtr, where you can do : CComPtr< ISomeInterface > spX; // Dot notation here, because you are using CComPtr::CoCreateInstance HRESULT hr = spX.CoCreateInstance(...); // Arrow notation here, because we are accessing wrapped interface methods hr = spX->DoSomethingWithX(...); > You did not say what you mean by "crash", which is essentially a > meaningless term as you > have used it. When this error occurs, something VERY SPECIFIC is > displayed on your screen > to indicate the problem, and you have not said what that is. I agree, of course. :) Giovanni
From: Lasse on 8 May 2008 08:10 The problem is a not existing call to CoInitialize(0); With this it works....
From: Joseph M. Newcomer on 8 May 2008 11:32
Then this is an instance of one of those posts that fails to give all the critical information. Any request for help that includes a code fragment should include all the declarations of the variables involved! joe On Thu, 8 May 2008 11:40:22 +0200, "Giovanni Dicanio" <giovanni.dicanio(a)invalid.com> wrote: > >"Joseph M. Newcomer" <newcomer(a)flounder.com> ha scritto nel messaggio >news:n8m424dh1b6qf4h2m9m78gdq7b8q97br4r(a)4ax.com... > >> Also, you declare _hisdllfunc ptr, you do ptr.CreateInstance, but then >> you do >> ptr->dothething. This should not even compile. Either ptr is an object, >> or it is a >> pointer to an object. > >Hi Joe, > >I think that OP's 'ptr' is a smart pointer. So it can have methods like >CreateInstance, that are correctly called using dot notation. And the smart >pointer overloads operator->, so the OP can call the original interface >methods (like 'dothething') using operator->. > >It's similar to CComPtr, where you can do : > > CComPtr< ISomeInterface > spX; > > // Dot notation here, because you are using CComPtr::CoCreateInstance > HRESULT hr = spX.CoCreateInstance(...); > > // Arrow notation here, because we are accessing wrapped interface methods > hr = spX->DoSomethingWithX(...); > > >> You did not say what you mean by "crash", which is essentially a >> meaningless term as you >> have used it. When this error occurs, something VERY SPECIFIC is >> displayed on your screen >> to indicate the problem, and you have not said what that is. > >I agree, of course. :) > >Giovanni > > Joseph M. Newcomer [MVP] email: newcomer(a)flounder.com Web: http://www.flounder.com MVP Tips: http://www.flounder.com/mvp_tips.htm |