[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 886
  • Last Modified:

Contamination from unmanaged code in managed VC++.NET

I am trying to merge a code which was translated from unmanaged to managed VC++.NET with another piece of code which was managed to begin with. Each one of these codes compiles fine. However, when I merge them unexpected errors show up. For instance, in the merged code I have explicitly written:

windir = System::Environment::GetEnvironmentVariable("windir");

However, I receive the following error:

Form1.h(37): error C2039: 'GetEnvironmentVariableA' : is not a member of 'System::Environment'

'GetEnvironmentVariableA' is nowhere to be found in my merged code unless some #include invokes it from somewhere and makes it replace what I actually have in the merged code. What might be the reason for all that?
0
judico
Asked:
judico
  • 4
  • 4
1 Solution
 
nonubikCommented:
GetEnvironmentVariable is a macro for GetEnvironmentVariableA or GetEnvironmentVariableW (whether UNICODE or not) declared in <winbase.h> which is included in <windows.h>

The reason you get thi is because you include windows.h directly or indirectly.
To get rid of this compile error, you can just
   #undef GetEnvironmentVariable
before you use it.
0
 
judicoAuthor Commented:
So #include "windows.h" (coming from the part of the code that was translated from unmanaged) messes up, after the merger, the part of the code that was managed to begin with. Now, I included, as you suggested, #undef GetEnvironmentVariable and it took care of  some errors but other errors still remain, such as:

error C2143: syntax error : missing ';' before '*'
temperature.h(45): error C2501: 'Q307398::temperature::MultiMeter' : missing storage-class or type specifiers
temperature.h(45): error C2501: 'Q307398::temperature::mmeter' : missing storage-class or type specifiers

How can I get rid of those errors too? Isn't there some clean way to get rid of the unmanaged code altogether?
0
 
nonubikCommented:
The new error you posted looks like managed code.
The line 45 and 44 from temperature.h are needed in order to see what's on.
0
Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

 
judicoAuthor Commented:
These are lines 44 and 45 are:

private: int evtCounter;
             MultiMeter *mmeter;

They work fine in the pre-merged code. Why don't they work here?
0
 
nonubikCommented:
maybe you need to use some namespace or something, like:
using namespace somenamespace
0
 
nonubikCommented:
Seems that the compiler does not know about "MultiMeter" data type. Maybe you need to include some header file.
0
 
judicoAuthor Commented:
Thanks a lot. The was exactly it. All the best.

judico
0
 
judicoAuthor Commented:
Thanks a lot. This was exactly it. All the best.

judico
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

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.

  • 4
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now