[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now


Using unmanaged C++ Visual C++.Net

Posted on 2004-08-12
Medium Priority
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
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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.
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.


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

Tech or Treat!

Submit an article about your scariest tech experience—and the solution—and you’ll be automatically entered to win one of 4 fantastic tech gadgets.

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++ (http://www.experts-exchange.com/viewArticle.jsp?aid=1193) I described how to encrypt text and recommended that the encrypted text be stored as a series of hexadecimal digits -- because cyphertext may…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…
Suggested Courses

656 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