Using unmanaged C++ Visual C++.Net

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
Compiled
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
Compiled
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.
SKKayesAsked:
Who is Participating?

Improve company productivity with a Business Account.Sign Up

x
 
RomModConnect With a Mentor Commented:
Closed, points refunded.
RomMod
Community Support Moderator
0
 
drichardsCommented:
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?
0
 
SKKayesAuthor Commented:
Here's the wrapper class

#pragma once
#include "TLKEditor.h"

using namespace System::Runtime::InteropServices;

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

private:
      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
{
public:
      TLKEditor();
      TLKEditor(const string& fileName);
      TLKEditor(const char* fileName);
      ~TLKEditor();
      void OpenTLKFile(const string& fileName);
      
      void SaveTLKFile(const string& fileName);
      
      
//Trying to use manage C++
private:
      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);
private:
      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&);

private:
      int nFlags;
      char cSoundRes [16];
      int nVolumeVar;
      int nPitchVar;
      int nOffset;
      int nStringSize;
      float fSoundLen;
      StringData();
public:
      enum FlagType
      {
      TXT_PRESENT = 0x0001,
      SND_PRESENT = 0x0002,
      SND_LEN_PRESENT = 0x0004,
      };
      StringData(int);
      
      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
http://www.dnbnet.org/Experts-Exchange/

If someone wants to play with it and find the oopsie I made.
0
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.

 
SKKayesAuthor Commented:
Oh I forgot to mention I don't explicitly include cstdio, it's coming from fstream.
0
 
SKKayesAuthor Commented:
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.
0
 
drichardsCommented:
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.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.