?
Solved

including exe file and using uuidof

Posted on 2009-12-17
9
Medium Priority
?
553 Views
Last Modified: 2013-12-14
I am attempting to use a keyboard application within a visual c++ solution. I have copied their example and put the following lines in the beginning of the cpp file:

#import "C:\Program Files\MountFocus\Keyboard\Kbd.exe"

Kbd::ImfSoftkeysPtr keybd(__uuidof(Kbd::mfSoftkeys));

If i run the solution I don't have a problem. My problem comes in when I execute the resulting exe from within another solution using CreateProcess. When I try to create the process it aborts. The main application still runs, but the one I am attempting to execute aborts with "This application ha srequested the Runtime to terminate it in an unusual way"

I am not well versed in C++, so any advice is appreciated!
0
Comment
Question by:jadixon
  • 5
  • 4
9 Comments
 
LVL 31

Expert Comment

by:Zoppo
ID: 26078334
Hi jadixon,

first I would suggest to debug it, since you cannot be sure the problem is related to the posted code.

You can debug you own application when loaded by the calling process this way:
- open your app in Visual Studio
- open 'Project->Properties', select 'Configuration Properties->Debugging'
- enter the path of the calling app in 'Command'
- start debugging.

Now the calling app will be started and maybe thus you can find where exactly your app fails.

Hope that helps,

ZOPPO
0
 

Author Comment

by:jadixon
ID: 26079654
I am using the debugger. Right now I have $(TargetPath) as the "command" entry.

I know the code aborts when I have the statement with the __uuidof  included. If I comment it out and do not try to access the keybd variable, all is fine. Once I uncomment the __uuidof line (even if I don't reference the keybd variable) the subordinate application blows up and it does not break where I can look at the call stack (or much else).

As I said, if I run the subordinate application on its own it runs just fine.

0
 
LVL 31

Expert Comment

by:Zoppo
ID: 26079886
> I am using the debugger. Right now I have $(TargetPath) as the "command" entry.
IMO with using $(TargetPath) as 'command' you cannot debug this problem, cause in this case you can either debug the calling process or the subordinate application called standalone.

If you debug the subordinate application using the calling application's executable as 'command' IMO you should see where it crashs.

BTW: How do you start the subordinate process?

ZOPPO
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 

Author Comment

by:jadixon
ID: 26083494
Maybe I am still doing something wrong, but when I put the .exe file name into the 'command' it still aborts and does not let me get into the debugger.

To run the subordinate application I can either run it in visual studio loaded as its own project or from within the man project by selecting it then running.
0
 

Author Comment

by:jadixon
ID: 26083511
Did you mean how to I start the subordinate process from within the main? If that is what you meant I am using CreateProcess
0
 

Author Comment

by:jadixon
ID: 26108179
One thing I have found after attempting to get this working is that if I place the

Kbd::ImfSoftkeysPtr keybd(__uuidof(Kbd::mfSoftkeys));

statement within the OnInitDialog() it no longer aborts. However, it makes keybd a local variable so none of the other event functions can see it.

Can anyone help me with declaring keybd at the top of the cpp file and put the __uuidof down into the OnInitDialog? I can't seem to find how to do that.
0
 
LVL 31

Expert Comment

by:Zoppo
ID: 26110667
Hi,

maybe it otherwise gets instantiated too early.

Does it have to be a singleton which you can access from elsewhere? If so I'd suggest to implement a littler helper class like this:

class KbdHelper
{
 static Kbd::ImfSoftKeysPtr CreateInstance()
 {
  static Kbd::ImfSoftkeysPtr keybd(__uuidof(Kbd::mfSoftkeys));
  return keybd;
 }
public:
 static Kbd::ImfSoftKeysPtr GetInstance()
 {
  static Kbd::ImfSoftkeysPtr& keybd = CreateInstance();
  return keybd;
 }
};

With this you can access the object from wherever you include this class via:

> KbdHelper::GetInstance()

but, the difference is the instance is first created when you call it, i.e. if you call it the first time from your OnInitDialog.

Hope that helps,

ZOPPO
0
 

Accepted Solution

by:
jadixon earned 0 total points
ID: 26111868
I found a way to make it work. It may not be clean, but it works.

At the top of my cpp file I have

#import "C:\Program Files\MountFocus\Keyboard\Kbd.exe"

Kbd::ImfSoftkeysPtr keybd;

Then in the OnInitDialog() i have

      CoInitialize(0);
      Kbd::ImfSoftkeysPtr keybd2(__uuidof(Kbd::mfSoftkeys));
      keybd = keybd2;

It's cheating a bit, but it works!
0
 
LVL 31

Expert Comment

by:Zoppo
ID: 26112023
Yes, this is another solution to the same problem which is that it's somehow undefined when the global variable 'keybd' is instantiated.

Allthough I find my suggested solution (using a class with static methods) is nicer yours is ok and should work fine too.

ZOPPO
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this article, I'll describe -- and show pictures of -- some of the significant additions that have been made available to programmers in the MFC Feature Pack for Visual C++ 2008.  These same feature are in the MFC libraries that come with Visual …
Here is a helpful source code for C++ Builder programmers that allows you to manage and manipulate HTML content from C++ code, while also handling HTML events like onclick, onmouseover, ... Some objects defined and used in this source include: …
THe viewer will learn how to use NetBeans IDE 8.0 for Windows to perform CRUD operations on a MySql database.
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Suggested Courses

807 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question