Using unmanaged C++ Visual C++.Net

Posted on 2004-08-12
Last Modified: 2012-08-13
I'm new to using managed C++ and am trying to add unmanged C++ code for editing a file type into a new snazzy .Net application. I tried the It Just Works method, and It Just Didn't Work. So I tried creating a wrapper for my file editor. It still didn't work. Basically I'm getting all kinds of compilation errors from the cstdio library. I'm gettign errors such as fpos_t is not a member of global namespace, and fpos_t can not be used in a using decleration.  I'm hoping I'm just missing some simple step that will finally enable my code to work. Here are the steps I took for each of the above methods.

ITJW Method:
Copied Libraries to new project file.
Added them to the project
Put #include "TLKEditor.H"
created a new TLKEditor Object
Got lots of errors

Wrapper method
Created a __gc class TLKInterface
created wrapper methods for the constructor, destructor and all public methods
Removed references from the ITJW method
included my TLKInterface class
created a TLKInterface object
Got lots of errors

I'm kind of stuck at this point.  I want the application I'm writing to be relatively cross platform (besides the UI) so I don't want to go back and convert the libraries to managed code. Any ideas? If needed I can email the VS.Net project file for debugging.
Question by:SKKayes
  • 3
  • 2
LVL 19

Expert Comment

ID: 11788428
What else are you #include'ing before cstdio?  cstdio should compile cleanly, so something else is probably wrong.  Can you share the TLKEditor.h file or at least post the first couple of specific errors?

Author Comment

ID: 11790294
Here's the wrapper class

#pragma once
#include "TLKEditor.h"

using namespace System::Runtime::InteropServices;

__gc class TLKInterface
      TLKInterface(){tlkEditor = new TLKEditor();};
      TLKInterface(System::String* fileName);
      ~TLKInterface(){delete tlkEditor;};
      void OpenTLKFile(System::String* fileName);
      void SaveTLKFile(System::String* fileName);

      TLKEditor* tlkEditor;
      void toSTLString(System::String*, string&);
      System::String* toSystemString(const string&);

Here is the TLK Editor class

#pragma once
#include <string>
#include <fstream>
using namespace std;

#include "TLKFile.h"

class TLKEditor
      TLKEditor(const string& fileName);
      TLKEditor(const char* fileName);
      void OpenTLKFile(const string& fileName);
      void SaveTLKFile(const string& fileName);
//Trying to use manage C++
      void OpenTLKFile(const char* fileName);
      void SaveTLKFile(const char* fileName);
      void DeleteCurrentTLKFile();
      string GetString(int nIndex) const;
      void SetString(int nIndex, const string& toSet);
      void SetString(int nIndex, const char* toSet);
      void NewString(const string&);
      void NewString(const char*);
      void DeleteString(int);
      int GetSize();
      //Not implemented yet
      //void NewString(const string&, const string&, float soundLen = 0.0);
      //void SetString(int nIndex, const string&, const string&, float soundLen = 0.0);
      //void PadTLK(int);
      TLKFile* tlkFile;
      void updateOffsets();

The TLKFile class

#include <vector>
#include <fstream>
#include "TLKExceptions.h"
using namespace std;

class TLKFile;
class TLKEditor;
struct Header;
class StringData;

struct Header
      char cFileType [4];
      char cFileVer [4];
      int nLangID;
      int nStringCount;
      int nStringOffset;

class StringData
      //Remove this friend decleration all manipulation moved to editor
      friend class TLKFile;
      friend class TLKEditor;
      friend ifstream& operator >> (ifstream&, StringData&);
      friend ofstream& operator << (ofstream&, StringData&);
      friend ifstream& operator >>(ifstream& file, TLKFile& tlkFile);
      friend ofstream& operator << (ofstream&, TLKFile&);

      int nFlags;
      char cSoundRes [16];
      int nVolumeVar;
      int nPitchVar;
      int nOffset;
      int nStringSize;
      float fSoundLen;
      enum FlagType
      TXT_PRESENT = 0x0001,
      SND_PRESENT = 0x0002,
      SND_LEN_PRESENT = 0x0004,
      StringData(const string&, const string&, float soundLen = 0.0);


The first 4 errors I'm getting are
D:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\cstdio(17): error C2039: 'fpos_t' : is not a member of 'operator``global namespace'''

D:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\cstdio(17): error C2873: 'fpos_t' : symbol cannot be used in a using-declaration

D:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\cstdio(18): error C2039: 'clearerr' : is not a member of 'operator``global namespace'''

D:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\cstdio(18): error C2873: 'clearerr' : symbol cannot be used in a using-declaration
 All of the errors are from cstdio.

The project files and source code can be downloaded from

If someone wants to play with it and find the oopsie I made.

Author Comment

ID: 11790300
Oh I forgot to mention I don't explicitly include cstdio, it's coming from fstream.
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.


Author Comment

ID: 11790661
I solved the problem by including the stdafx.h file in the cpp's and using precompiled headers. I have No Idea why that solved the problem, which sucks, but it got me moving again.
LVL 19

Expert Comment

ID: 11793292
It fixes things because stdafx.h is where all the basic windows headers get included and by default the project settings require it.  If you turn off precompiled headers so you don't need to include stdafx.h, you need to manually include all the windows headers.  This is <windows.h> usually.  Look at  stdafx.h to see what really got included.

Accepted Solution

RomMod earned 0 total points
ID: 11826553
Closed, points refunded.
Community Support Moderator

Featured Post

U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

Question has a verified solution.

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

The following diagram presents a diamond class hierarchy: As depicted, diamond inheritance denotes when two classes (e.g., CDerived1 and CDerived2), separately extending a common base class (e.g., CBase), are sub classed simultaneously by a fourt…
In Easy String Encryption Using CryptoAPI in C++ ( I described how to encrypt text and recommended that the encrypted text be stored as a series of hexadecimal digits -- because cyphertext may…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
In a recent question ( here at Experts Exchange, a member asked how to add page numbers to a PDF file using Adobe Acrobat XI Pro. This short video Micro Tutorial sh…

770 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