<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[problem: ein char von einer funktion per strcpy() in ein in private: char zu kopieren, please help!]]></title><description><![CDATA[<p>Hallo, ich habe mir eine class erstellt mit der ich ein einfaches fenster erstelle, weiter gehend habe ich eine DialogProc Funktion. So nun habe ich in der class =&gt; private: einen char workstring[128]; und in der DialogProc will ich den aus einer EDITTEXT box geschriebenen text auslesen und in den workstring sichern.<br />
Also das ganze hab ich mir eigentlich so vorgestellt:</p>
<pre><code class="language-cpp">#ifndef _WINDOW_H
#define _WINDOW_H

    class window {

        public:

            window( char *ti, int wi, int he );
            ~window();
            int Start();
            char workstring[128];

        private:

            static LRESULT CALLBACK WindowProc( HWND, UINT, WPARAM, LPARAM );
            static LRESULT CALLBACK DialogProc( HWND, UINT, WPARAM, LPARAM );
            HINSTANCE hInst;
            HWND hWnd;
            WNDCLASS wc;
            MSG msg;

            char *szName;
            char *title;
            int width;
            int height;

        };

        int window::Start() {

            while( GetMessage( &amp;msg, 0, 0, 0 ) ) {

                TranslateMessage( &amp;msg );
                DispatchMessage( &amp;msg );

            }
            return msg.wParam;
        }

        window::window( char *ti, int wi, int he ) {

            szName = &quot;Window&quot;;
            title = ti;
            width = wi;
            height = he;

            […]
        }

        window::~window() {

            DestroyWindow( hWnd );
            hWnd = 0;

            UnregisterClass( szName, hInst );
            hInst = 0;
        }

        LRESULT CALLBACK window::WindowProc( HWND hWnd, UINT msg, WPARAM    wParam,
                                             LPARAM lParam ) {

            HINSTANCE hInst;

            switch( msg ) {

               case WM_CREATE: {

                DialogBox ( hInst , &quot;Dialog&quot; , hWnd ,
                                MakeProcInstance( (DLGPROC)DialogProc , hInst )) ;
                    return 0;
               }
	[…]
        }

        LRESULT CALLBACK window::DialogProc( HWND hWnd , UINT msg, WPARAM wParam,
                                             LPARAM lParam ) {

            char cstring[128];

            switch( msg ) {

                case WM_INITDIALOG: {

                    return true;
                }

                case WM_COMMAND: {

                    switch( wParam ) {

                        case IDOK: {

                            GetDlgItemText( hWnd, 105, cstring, sizeof( cstring ) ); 
                            strcpy( workstring, cstring );
                            return true;
                        }

                        case IDCANCEL: {

                            EndDialog( hWnd, 0 );
                            return true;
                        }
                    }
                    return true;
                }
            }
            return false;
        }

#endif
</code></pre>
<p>Ich habe in der DialogProc noch ein char erstellt um mit strcpy() diesen in workstring zu kopieren. Ich bekomme folgenden fehler:</p>
<pre><code>[C++ Error] wnd.h(149): E2231 Member window::workstring cannot be used without an object
</code></pre>
<p>Könnte mir bitte jemand mal erklären was ich vergessen habe?, danke.</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/164053/problem-ein-char-von-einer-funktion-per-strcpy-in-ein-in-private-char-zu-kopieren-please-help</link><generator>RSS for Node</generator><lastBuildDate>Sun, 13 Sep 2026 17:34:33 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/164053.rss" rel="self" type="application/rss+xml"/><pubDate>Sat, 04 Nov 2006 16:49:50 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to problem: ein char von einer funktion per strcpy() in ein in private: char zu kopieren, please help! on Sat, 04 Nov 2006 16:49:50 GMT]]></title><description><![CDATA[<p>Hallo, ich habe mir eine class erstellt mit der ich ein einfaches fenster erstelle, weiter gehend habe ich eine DialogProc Funktion. So nun habe ich in der class =&gt; private: einen char workstring[128]; und in der DialogProc will ich den aus einer EDITTEXT box geschriebenen text auslesen und in den workstring sichern.<br />
Also das ganze hab ich mir eigentlich so vorgestellt:</p>
<pre><code class="language-cpp">#ifndef _WINDOW_H
#define _WINDOW_H

    class window {

        public:

            window( char *ti, int wi, int he );
            ~window();
            int Start();
            char workstring[128];

        private:

            static LRESULT CALLBACK WindowProc( HWND, UINT, WPARAM, LPARAM );
            static LRESULT CALLBACK DialogProc( HWND, UINT, WPARAM, LPARAM );
            HINSTANCE hInst;
            HWND hWnd;
            WNDCLASS wc;
            MSG msg;

            char *szName;
            char *title;
            int width;
            int height;

        };

        int window::Start() {

            while( GetMessage( &amp;msg, 0, 0, 0 ) ) {

                TranslateMessage( &amp;msg );
                DispatchMessage( &amp;msg );

            }
            return msg.wParam;
        }

        window::window( char *ti, int wi, int he ) {

            szName = &quot;Window&quot;;
            title = ti;
            width = wi;
            height = he;

            […]
        }

        window::~window() {

            DestroyWindow( hWnd );
            hWnd = 0;

            UnregisterClass( szName, hInst );
            hInst = 0;
        }

        LRESULT CALLBACK window::WindowProc( HWND hWnd, UINT msg, WPARAM    wParam,
                                             LPARAM lParam ) {

            HINSTANCE hInst;

            switch( msg ) {

               case WM_CREATE: {

                DialogBox ( hInst , &quot;Dialog&quot; , hWnd ,
                                MakeProcInstance( (DLGPROC)DialogProc , hInst )) ;
                    return 0;
               }
	[…]
        }

        LRESULT CALLBACK window::DialogProc( HWND hWnd , UINT msg, WPARAM wParam,
                                             LPARAM lParam ) {

            char cstring[128];

            switch( msg ) {

                case WM_INITDIALOG: {

                    return true;
                }

                case WM_COMMAND: {

                    switch( wParam ) {

                        case IDOK: {

                            GetDlgItemText( hWnd, 105, cstring, sizeof( cstring ) ); 
                            strcpy( workstring, cstring );
                            return true;
                        }

                        case IDCANCEL: {

                            EndDialog( hWnd, 0 );
                            return true;
                        }
                    }
                    return true;
                }
            }
            return false;
        }

#endif
</code></pre>
<p>Ich habe in der DialogProc noch ein char erstellt um mit strcpy() diesen in workstring zu kopieren. Ich bekomme folgenden fehler:</p>
<pre><code>[C++ Error] wnd.h(149): E2231 Member window::workstring cannot be used without an object
</code></pre>
<p>Könnte mir bitte jemand mal erklären was ich vergessen habe?, danke.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1168382</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1168382</guid><dc:creator><![CDATA[T0bi]]></dc:creator><pubDate>Sat, 04 Nov 2006 16:49:50 GMT</pubDate></item><item><title><![CDATA[Reply to problem: ein char von einer funktion per strcpy() in ein in private: char zu kopieren, please help! on Sat, 04 Nov 2006 17:00:26 GMT]]></title><description><![CDATA[<p>DialogProc ist eine statische Funktion. Statische Funktionen können keine nicht-statischen Member nutzen, ohne das explizit das Objekt angegeben wird.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1168384</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1168384</guid><dc:creator><![CDATA[Z2]]></dc:creator><pubDate>Sat, 04 Nov 2006 17:00:26 GMT</pubDate></item><item><title><![CDATA[Reply to problem: ein char von einer funktion per strcpy() in ein in private: char zu kopieren, please help! on Sat, 04 Nov 2006 18:22:37 GMT]]></title><description><![CDATA[<p>und wie gebe ich dieses objekt nun explizit an??? sry is bei mir glaube noch ne bildungs lücke -..</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1168452</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1168452</guid><dc:creator><![CDATA[T0bi]]></dc:creator><pubDate>Sat, 04 Nov 2006 18:22:37 GMT</pubDate></item><item><title><![CDATA[Reply to problem: ein char von einer funktion per strcpy() in ein in private: char zu kopieren, please help! on Mon, 06 Nov 2006 14:05:45 GMT]]></title><description><![CDATA[<p>Hi,</p>
<p>vermutlich gar nicht !<br />
Das gibt das Schnittstellendesign nicht her. Eine static-Memberfunktion unterscheidet sich nicht von einer &quot;freien Funktion in einem namespace&quot; ... und nur eine solche nimmt offensichtlich die Funktion, über die Du die Callbackfunktion registrierst, entgegen.</p>
<p>Du solltest schauen, was Dir der Caller in den Parametern HWND, UINT, WPARAM, LPARAM übergibt und ob Du Dir daraus evtl. ein geeignetes window-Objekt konstruieren kannst (z.B. über ein &quot;getWindow(HWND)&quot; o.ä.; oder Du baust Dir ein Neues innerhalb Deiner Callbackfunktion).</p>
<p>Gruß,</p>
<p>Simon2.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1169671</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1169671</guid><dc:creator><![CDATA[Simon2]]></dc:creator><pubDate>Mon, 06 Nov 2006 14:05:45 GMT</pubDate></item></channel></rss>