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.
How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline


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

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

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…
Internet Business Fax to Email Made Easy - With eFax Corporate (, you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

758 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now