Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

I'm having a few probs, I think it may have to do with converting?

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
Hi, I'm kinda new to the C++ community and I'm having a problem. A good friend left me some closed source code, and put a lot of hard work into it. He's moving to Russia, so he's all done with the project.

Now let me tell you one thing, this guy is a literal genious, so I doubt the code has as many errors as MSVC++ states it has. Friend tell me that it may be because he used a different compiler, or the language is different, I dont know. But any help would be appreciated.

Heres a sample error:

Compiling...
graysvr.cpp
c:\program files\icq\received files\menace\common\cscriptobj.h(101) : error C2664: 'wvsprintfA' : cannot convert parameter 1 from 'char' to 'char *'
Conversion from integral type to pointer type requires reinterpret_cast, C-style cast or function-style cast
c:\program files\icq\received files\menace\common\cscriptobj.h(102) : error C2664: 'SysMessage' : cannot convert parameter 1 from 'char' to 'const char *'
Conversion from integral type to pointer type requires reinterpret_cast, C-style cast or function-style cast


Basically, heres the code portion:

class CTextConsole
{
// A base class for any class that can act like a console and issue commands.
// CClient, CChar, CServer, CFileConsole
protected:
int OnConsoleKey( CGString & sText, TCHAR nChar, bool fEcho );
public:
// What privs do i have ?
virtual CAccountRef GetAccount() const
{
return NULL;
}
virtual PLEVEL_TYPE GetPrivLevel() const = 0;
virtual LPCTSTR GetName() const = 0; // ( every object must have at least a type name )
virtual CChar * GetChar() const; // are we also a CChar ? dynamic_cast ?

virtual void SysMessage( LPCTSTR pszMessage, WORD wHue = 0 ) const = 0; // Feed back message.
int VSysMessage( LPCTSTR pszFormat, va_list args ) const
{
TCHAR szTemp;
size_t ilen = vsprintf( szTemp, pszFormat, args );
SysMessage( szTemp );
return( ilen );
}
int _cdecl SysMessagef( LPCTSTR pszFormat, ... ) const
{
va_list vargs;
va_start( vargs, pszFormat );
int iRet = VSysMessage( pszFormat, vargs );
va_end( vargs );
return( iRet );
}
};






This error really gets me too:

c:\program files\icq\received files\menace\graysvr\graysvr.cpp(92) : error C2078: too many initializers


It looks like this in the code:

LPCTSTR const g_Stat_Name = // not sorted obviously.
{
"STR",
"INT",
"DEX",
"KARMA",
"FAME",

// "OSTR",
// "OINT",
// "ODEX",
// "MAXHITS",
// "MAXMANA",
// "MAXSTAM",
};

Where as INT is intellegence, (for a game emulator)
Any help in this would be GREATLY appreciated, thanks.
 
1. First problem:
Change the line:
size_t ilen = vsprintf( szTemp, pszFormat, args );

into

size_t ilen = vsprintf( &szTemp, pszFormat, args );

2.Second problem:
This comes from a bigger number of initializers than the number of objects to be initialized.

g_Stat_Name -is probablty declared as having a size smaller than 5, and you have 5 elements to initialize. Also try to take out the coments from the initialization , the compiler might interpret thm as a suplemenary initializer because of the last commas.

Hope this helps,
s-)

Blessed is he who in the name of justice and good will, shepards the week through the valley of darkness...
 
The problem you have seems to me to be the array declaration, which is merely a pure string, rather than an array of strings.

So, try to change the declaration to
Code:
 LPCTSTR const g_Stat_Name[] =  {// the rest of the code

And one other thing. TCHAR is a Windows thing, meaning that the actual output of the compiler depends on some defined symbols fed to it (_UNICODE, for ex.). That means that if you are in the US, TCHAR will most probably be an 8 bit ASCII character, but if wou are in Japan, could be a 16 bit Unicode.

Anyway, the idea is the your variable szTemp is a CHARACTER, not a string! And SysMessage function requires a string, so you might want to say
Code:
 TCHAR * szTemp;
and allocate and deallocate memory for it, or merely
say
Code:
TCHAR szTemp[100]
or something like that.

Hope this helps.

P.S. Another thing is an extra comma in the initializer list of the g_stat_name variable, just before the comments start.
Nosferatu
We are what we eat...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top