Solved

Using unmanaged C++ Visual C++.Net

Posted on 2004-08-12
7
1,045 Views
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
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.
0
Comment
Question by:SKKayes
  • 3
  • 2
7 Comments
 
LVL 19

Expert Comment

by:drichards
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?
0
 

Author Comment

by:SKKayes
ID: 11790294
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
 

Author Comment

by:SKKayes
ID: 11790300
Oh I forgot to mention I don't explicitly include cstdio, it's coming from fstream.
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

Author Comment

by:SKKayes
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.
0
 
LVL 19

Expert Comment

by:drichards
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.
0
 

Accepted Solution

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

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

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…
Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…
This is used to tweak the memory usage for your computer, it is used for servers more so than workstations but just be careful editing registry settings as it may cause irreversible results. I hold no responsibility for anything you do to the regist…

861 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

23 Experts available now in Live!

Get 1:1 Help Now