CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 13 of 13
  1. #1
    Join Date
    Dec 2011
    Location
    Bucharest, Romania
    Posts
    29

    Lightbulb classes in visualstudio

    Hi,
    I`m using msvcc6 and start writing a program that relates to dx-audio. Msdn says to make use of error codes such as display windows for translating the error codes into error messages so I setup a (class) cError method w public members:

    file:cpterr.cpp
    [code]
    [size=-2][center]
    ====================================================================
    Code:
    #include"cpterr.h";
    #include <windows.h>;
    void crep::mb(CHAR* msg, CHAR* ttl){
    PSTR temp;
    	MessageBoxA(0, msg, ttl, MB_OK);
    	if (lstrcmpi(ttl, __TEXT("exit")))
    	MessageBoxA(0, "please shut down", ttl, MB_OK);
    }
    
    DWORD crep::getrr(DWORD ol,LPSTR nume2){
    	CHAR ctemp[127]="\0";
    	if (ol!=0l) {
    		mciGetErrorString(ol, ctemp,sizeof(ctemp));
    		wsprintfA(ctemp,"return err#:&#37;d;\napi mesage:%s;\ninterpret %s",ol,ctemp,nume2);
    	MessageBoxA(0, ctemp, "line12-getrr", MB_ICONQUESTION);
    	};
    	return (ol);
    }
    
    void *crep::operator new( size_t stAllocateBlock, char chInit ){
        void *pvTemp = malloc( stAllocateBlock );
        if( pvTemp != 0 )
            memset( pvTemp, chInit, stAllocateBlock );
        return pvTemp;
    }[\code]
    ====================================================================
    [\center][\size]

    ,prototypes in:"cpterr.hhh"
    [size=-2][center]====================================================================
    Code:
    //#include"cpterr.cpp"
    typedef public class creptag{
    public:
    	void *operator new( size_t stAllocateBlock, char chInit );
    	crep(void);
    	~crep();
    	DWORD getrr(DWORD ol,LPSTR nume2);//explicitare erori mci?////prototip elem. nou adaugat
    	void mb(CHAR* msg, CHAR* ttl);	//message box
    
    private:
    	int classe;
    } CREP;
    ====================================================================
    [\center][\size]-twas declaration-matrix


    [size=-2][center]
    =================================================================
    Code:
    "main.cpp"
    #include "cpterr.h"				//classs w fatale__class
    #include "ext4.cpp"				//global vars
    #include "ext3.cpp"				//dx7 procs
    ;
    =================================================================
    [\center][\size]


    By now I have acces build use a cerro variable in another file:
    [size=-10][center]
    =================================================================
    Code:
    "ext3.cpp"
    // Global Variables:
    //fw declaration of procss:
    //ATOM
    //...
    //file accessing whit err
    BOOL StartWrite(TCHAR* /*pszFileName*/);//write chunk
    BOOL StopWrite(void);				//!!
    HRESULT WaveOpenFile(LPSTR /*strFileName*/, HMMIO /*phmmioOut*/,//!=0!
    				 WAVEFORMATEX* /*pwfxDest*/,
    				 MMCKINFO* /*pckOut*/,
    				 MMCKINFO* /*pckOutRIFF*/);	
    BOOL WaveStartDataWrite(HMMIO /*phmmioOut*/,
    			MMCKINFO* /*pckOut*/,//initializes one datachunkfor fileflush
    			MMIOINFO /*pmmioinfoOut*/ );
    HRESULT WaveWriteFile( HMMIO hmmioOut, UINT cbWrite, BYTE* pbSrc,
                           MMCKINFO* pckOut, UINT* cbActualWrite, 
                           MMIOINFO* pmmioinfoOut );
    HRESULT WaveCloseWriteFile( HMMIO* hmmioOut,  MMCKINFO* pckOut, MMCKINFO *pckOutRIFF,   
                                MMIOINFO *pmmioinfoOut, 
                                DWORD dwSamples );
    BOOL StreamToFile(void);	//copiaza bloc din buffer2 in fisier
    
    [size=-2]//#globale-vars
    CREP cerro;		//typedef for error variable
    //scope of main
    main(void){
    //....
    cerro.mb("mesage for autostart record","title");
    //....
    }
    =================================================================
    [\center][\size]

    [size=-2][center]
    ====================================================================
    Code:
    "main.cpp"
    #include "cpterr.h"			//define errorclass
    #include "ext3.h"				//defs  around-scop1
    #include "ext4.h"				//defs  another scope
    ;/eof
    ;====================================================================
    [\center][\size]

    But after it reports any kind of error and can`t instanciate cerro, starting w/

    [i]*<right side of .'mb' must be struct/class/union>
    *<'CREP ': missing storage class>...
    *<main.cpp(5)><unespected eof>[\i]


    Whole program use only 'the error reporting' class and spans over 3 files so far and class CREP is w/ no function container other than it shows. How to declare a CREP class for cerro-variable and make use its member *.mb like across var funct. Is a declaration
    CREP cerro; legal? How to use 'cerro globally?'

    =========================================================
    red tomato and patatoes for your kitchen @1pound
    Last edited by john wiley; December 30th, 2011 at 03:53 PM. Reason: i made this, ite

  2. #2
    Join Date
    Dec 2011
    Location
    Bucharest, Romania
    Posts
    29

    Thumbs up Re: classes in visualstudio

    error mess might have slight diff

  3. #3
    Join Date
    Sep 2004
    Location
    Holland (land of the dope)
    Posts
    4,123

    Re: classes in visualstudio

    Welcome to codeguru. Please use code tags. Your code isn't very readable without them.
    Code:
    class crep{
    public:
    ....
    } CREP;
    The class is names 'crep', not 'CREP'. This is usually done with structs, not classes.

  4. #4
    Join Date
    Dec 2011
    Location
    Bucharest, Romania
    Posts
    29

    Re: classes in visualstudio

    caps lock gets used for types in visual studio any class union struct there is. it means that a class type is available at the pick of your choise. capslockers gave messages
    [code][size=-10]_italic_
    <main.coo>requiring ';' before cerro declaration
    [\size][\code]
    Last edited by john wiley; December 30th, 2011 at 03:31 PM. Reason: lack of dropdown type4bbcodes

  5. #5
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,396

    Re: classes in visualstudio

    Quote Originally Posted by john wiley View Post
    file:cpterr.cpp
    ====================================================================
    Code:
    #include"cpterr.h";
    #include <windows.h>;
    void crep::mb(CHAR* msg, CHAR* ttl){
    PSTR temp;
    	MessageBoxA(0, msg, ttl, MB_OK);
    //if error code need restart, warn users
    	if (lstrcmpi(ttl, __TEXT("exit")))
    	MessageBoxA(0, "please shut down", ttl, MB_OK);
    //	return 0l;
    }...
    Replace your includes with
    Code:
    #include <windows.h>
    #include "cpterr.h"
    Quote Originally Posted by john wiley View Post
    ,and prototype in:cpterr.h
    Code:
    class crep{
    public:
    	void *operator new( size_t stAllocateBlock, char chInit );
    	crep(void);
    	~crep();
    //public:
    	DWORD getrr(DWORD ol,LPSTR nume2);//explicitare erori mci?////prototip elem. nou adaugat
    	void mb(CHAR* msg, CHAR* ttl);	//message box
    
    private:
    	int classe;
    } CREP;
    Add typedef before the class

    Quote Originally Posted by john wiley View Post

    Code:
    #include "cpterr.h"			//define fataleclass
    main(void){
    CREP cerro;				//(extern) CREP cerro
    ....
       cerro.mb("mesage for autostart record","title");
    ....
    }
    Add
    Code:
    #include <windows.h>
    as the first line
    Last edited by VictorN; December 20th, 2011 at 12:37 PM.
    Victor Nijegorodov

  6. #6
    Join Date
    Dec 2011
    Location
    Bucharest, Romania
    Posts
    29

    Thumbs up Re: classes in visualstudio

    were you the only soul th2kindly checked and run it too ? It needs further work by me to improve
    Great now it works *)th$

    . __--------_
    . / >|< \|/, \
    .| / \ |
    .\ --______-' |
    . \ -- ___&#175; ,;
    . \--______-'
    Last edited by john wiley; December 26th, 2011 at 05:00 PM.

  7. #7
    Arjay's Avatar
    Arjay is offline Moderator / EX MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    13,490

    Re: classes in visualstudio

    You'll save yourself much headache later if you learn to leverage the string types defined in TCHAR.H and not explicitly call the A or W api's (i.e. don't call MessageBoxA, call MessageBox instead).

  8. #8
    Join Date
    Dec 2011
    Location
    Bucharest, Romania
    Posts
    29

    Re: classes in visualstudio

    many thanx , now let`s move on. I got following error.............................
    --------------------Configuration: main_win32 - Win32 Release--------------------
    Code:
    *Output Window
    *Compiling...
    *fonemtia_win32.cpp
    *Linking...
    *main_win32.obj : error LNK2001: unresolved external symbol "long __cdecl FreeDirectSound(void)" (?FreeDirectSound@@YAJXZ)
    *main_win32.obj : error LNK2001: unresolved external symbol "public: void __thiscall crep::mb(char *,char *)" (?mb@crep@@QAEXPAD0@Z)
    *main_win32.obj : error LNK2001: unresolved external symbol "long __cdecl WaveCloseWriteFile(struct HMMIO__ * *,struct _MMCKINFO *,struct _MMCKINFO *,struct _MMIOINFO *,unsigned long)" (?WaveCloseWriteFile@@YAJPAPAUHMMIO__@@PAU_MMCKINFO@@1PAU_MMIOINFO@@K@Z)
    *main_win32.obj : error LNK2001: unresolved external symbol "int __cdecl WaveStartDataWrite(struct HMMIO__ *,struct _MMCKINFO *,struct _MMIOINFO)" (?WaveStartDataWrite@@YAHPAUHMMIO__@@PAU_MMCKINFO@@U_MMIOINFO@@@Z)
    *main_win32.obj : error LNK2001: unresolved external symbol "public: unsigned long __thiscall crep::getrr(unsigned long,char *)" (?getrr@crep@@QAEKKPAD@Z)
    *Release/main_win32.exe : fatal error LNK1120: 5 unresolved externals
    *Error executing link.exe.

    choosing struct settled the solution; my class has option to store a function/procs such as crep.mb(), where ()is arg for function mb. I have fixed error by temporary using struct, now works ok.

    late news is beyond compiler errors (now fixed came up linker error. where is the problem in there?
    Last edited by john wiley; December 30th, 2011 at 03:36 PM. Reason: pizza hut, afi center mall, fraid chicken, small oranges, milka chocolate

  9. #9
    Join Date
    Feb 2003
    Location
    Iasi - Romania
    Posts
    8,234

    Re: classes in visualstudio

    Probably, you've got that stuff from one internet kiddie.
    Otherwise, I could not explain so many shuffled horrors in just few lines of code.

    First of all, try to get rid of C-style constructions like
    Code:
    class _CFoo
    {
       // ...
    }CFoo;
    as well as
    Code:
    typedef class _CFoo
    {
       // ...
    }CFoo;
    Note: C has not 'class' keyword but you can imagine replacing it with 'struct' to be a real C-geek.

    In C++, the usual class (or struct) definitions look like this one:
    Code:
    class CFoo
    {
      //...
    };
    Simplu ca "buna ziua!" (simple like "good day!").
    Besides, if using Visual Studio, a wizard can help you to properly add new classes.

    Second, overloading the new operator there, has no sense. Simply, remove it.
    Also WTH is that "please shut down"? Prompt the user for shut down because an MCI function has failed?
    C'mon... let's be serious!
    Ovidiu
    "When in Rome, do as Romans do."
    My latest articles: https://codexpertro.wordpress.com/

  10. #10
    Join Date
    Dec 2011
    Location
    Bucharest, Romania
    Posts
    29

    Re: classes in visualstudio

    I do not use special symbols in classes definitions &only declared it as typedef "}CREP;" .

    SPlitting functions in classes by scopes (one to report error in crep classe;another to display formatted messages by my template mb(,); and latter w/ headers in ext4.cpp) helps me centr3 macrofunctions. Then I use caption mess & code error ids using "resource wizard in visual environment."

    Is there a way to pass limitations in visual environment (if)to have prototype declared in a file and function-body deffined in a file directly accesible from very file?iMy way was to declare headers main file, some headers in a place, other elsewhere and global declarations in another not so straighforward accesibe from the prototype file -cpterr.h ? ("cpterr.h" does not have #include<?> sattements and neither "cpterr.cpp".)
    Last edited by john wiley; December 26th, 2011 at 04:58 PM.

  11. #11
    Join Date
    Feb 2003
    Location
    Iasi - Romania
    Posts
    8,234

    Re: classes in visualstudio

    Quote Originally Posted by john wiley View Post
    I do not use special symbols in classes definitions &only declared it as typedef "}CREP;" .

    SPlitting functions in classes by scopes (one to report error in crep classe;another to display formatted messages by my template mb(,); and latter w/ headers in ext4.cpp) helps me centr3 macrofunctions. Then I use caption mess & code error ids using "resource wizard in visual environment."

    Is there a way to pass limitations in visual environment (if) ...
    Please clarify what do you mean with

    1. use special symbols in classes definitions
    2. SPlitting functions in classes by scopes
    3. use caption mess & code error ids using "resource wizard in visual environment."
    4. pass limitations in visual environment (if)
    Last edited by ovidiucucu; December 27th, 2011 at 04:04 AM.
    Ovidiu
    "When in Rome, do as Romans do."
    My latest articles: https://codexpertro.wordpress.com/

  12. #12
    Join Date
    Dec 2011
    Location
    Bucharest, Romania
    Posts
    29

    Re: classes in visualstudio

    I did a small image:


    [img]
    http://www.freeimagehosting.net/t/93f19.jpg
    [/img]


    If you have the time read again and interpret it, pleass? Its a five files graph

  13. #13
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,396

    Re: classes in visualstudio

    Quote Originally Posted by john wiley View Post
    I did a small image:





    If you have the time read again and interpret it, pleass? Its a five files graph
    Please, attach your image to your post.
    Victor Nijegorodov

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured