473,785 Members | 3,417 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Calling a function from another class (dialog)

Hello Everyone,

This problem's been causing me a lot of trouble and I'm hoping
somebody can help me out!!

I have a dialog-based MFC application in visual studio 2003. I want to
call a function called "OnPrintMsg " from my dialog class called
"MyAppDlg.h ". The function needs to be called from another class called
"Client.cpp ". The Client class (derived from the CSockets class) exists
as described below.

MyAppDlg.h
....
CClient myclient; //The CClient class is another class that I created.
It inherits from CSocket.
void OnPrintMsg(); // This function is in my dialog application
....
//Client.cpp
CClient::OnRece ive() // This function is called from my Client Class
upon receiving information from
// the socket
....

OnPrintMsg(); //want to call function in MyApp dialog with access to
dialog member variables
In a nutshell what I want to do from the OnReceive, is like
CMyApp::OnPrint Msg(); However, when I tried this using a local instance
of the MyApp class, I was unable to access the member variable of the
actual dialog, likely because it was a local instance.

Can anyone help me? Thanks in advance!!

~ Ian

Dec 20 '06 #1
3 8634
dr**********@gm ail.com wrote:
Hello Everyone,

This problem's been causing me a lot of trouble and I'm hoping
somebody can help me out!!

I have a dialog-based MFC application in visual studio 2003. I want to
call a function called "OnPrintMsg " from my dialog class called
"MyAppDlg.h ". The function needs to be called from another class
called "Client.cpp ". The Client class (derived from the CSockets
class) exists as described below.

MyAppDlg.h
...
CClient myclient; //The CClient class is another class that I created.
It inherits from CSocket.
void OnPrintMsg(); // This function is in my dialog application
...
//Client.cpp
CClient::OnRece ive() // This function is called from my Client Class
upon receiving information from
// the socket
...

OnPrintMsg(); //want to call function in MyApp dialog with access to
dialog member variables
In a nutshell what I want to do from the OnReceive, is like
CMyApp::OnPrint Msg(); However, when I tried this using a local
instance of the MyApp class, I was unable to access the member
variable of the actual dialog, likely because it was a local instance.

Can anyone help me? Thanks in advance!!
This falls under FAQ 5.8 (and the rest of section 5), I believe.
Most likely you're in dire need of some education how to deal with
MFC classes. Isn't there a book or, like, a hundred, about those?
Try asking in a newsgroup dedicated to MFC. There are several.

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Dec 20 '06 #2
My problem isn't rooted in MFC, the problem is simply classes. The
problem is is I have a main class that has a member variable of another
class. A function within the member variable is called, and I want to
call a function of the main class. There is nothing strictly MFC about
the problem.

Thanks anyway

Victor Bazarov wrote:
dr**********@gm ail.com wrote:
Hello Everyone,

This problem's been causing me a lot of trouble and I'm hoping
somebody can help me out!!

I have a dialog-based MFC application in visual studio 2003. I want to
call a function called "OnPrintMsg " from my dialog class called
"MyAppDlg.h ". The function needs to be called from another class
called "Client.cpp ". The Client class (derived from the CSockets
class) exists as described below.

MyAppDlg.h
...
CClient myclient; //The CClient class is another class that I created.
It inherits from CSocket.
void OnPrintMsg(); // This function is in my dialog application
...
//Client.cpp
CClient::OnRece ive() // This function is called from my Client Class
upon receiving information from
// the socket
...

OnPrintMsg(); //want to call function in MyApp dialog with access to
dialog member variables
In a nutshell what I want to do from the OnReceive, is like
CMyApp::OnPrint Msg(); However, when I tried this using a local
instance of the MyApp class, I was unable to access the member
variable of the actual dialog, likely because it was a local instance.

Can anyone help me? Thanks in advance!!

This falls under FAQ 5.8 (and the rest of section 5), I believe.
Most likely you're in dire need of some education how to deal with
MFC classes. Isn't there a book or, like, a hundred, about those?
Try asking in a newsgroup dedicated to MFC. There are several.

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Dec 20 '06 #3
dr**********@gm ail.com wrote:
My problem isn't rooted in MFC, the problem is simply classes. The
problem is is I have a main class that has a member variable of another
class. A function within the member variable is called, and I want to
call a function of the main class. There is nothing strictly MFC about
the problem.
Quite true. To call a function of your "main" class from outside the
class you can use a pointer to the "main" class object. When you create
or initialize the member object pass it the 'this' pointer from the main
class. Store the pointer in a member variable and use it when need to
call functions in the "main" class object.

--
Scott McPhillips [VC++ MVP]

Dec 20 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

14
3013
by: ericellsworth | last post by:
Hi, I'm trying to use a class to pass variables back and forth from a form opened in dialog mode. I have created a class which invokes a form in its show method, like so: Public Sub Show() ' This method shows the form used to get the info If sWhereInt = "" Then DoCmd.OpenForm sFormNameInt, acNormal, , , acFormAdd, _
2
10763
by: Chi Tang | last post by:
Hi, I have 2 questions: How to call a class member function from another class and these 2 classes are in the same namespace? Also, how to use another project's dialog box and this 2 projects are in the same VS.NET solution?
3
10238
by: Alexander | last post by:
Me again.... second time I type this - the post did not work the first time... Similar question as last time, but another problem: I am running a CE.Net Application and I want to show a small borderless dialog which shows an animation, that shows, that the application is still doing something. So far it works until I want to close the dialog. The dialog has a delegate that I want to invoke, which will close it. But I run into a...
4
9879
by: Tim Menninger | last post by:
Just started working on this and have not found any real good resources out there. We have a lot of native C++ Dll code that we use for our app. We want to share the code so that C# ASP.net code can use the same business logic as our C++ client. Here are some questions: 1) Is there a way to call into native C++ classes directly? Meaning we do not have C API. I believe we could use a C API using the in C#. 2) If can't do #1, do we need...
5
3437
by: Nick Flandry | last post by:
I'm running into an Invalid Cast Exception on an ASP.NET application that runs fine in my development environment (Win2K server running IIS 5) and a test environment (also Win2K server running IIS 5), but fails on IIS 6 running on a Win2003 server. The web uses Pages derived from a custom class I wrote (which itself derives from Page) to provide some common functionality. The Page_Load handler the failing webpage starts out like this: ...
5
1578
by: z. f. | last post by:
Hi, I'm working on a web project and i create classes to do business logic and connect to DB. i also need a windows application to do the same functionality as defined in classes inside the ASP.NET project. when i reference the web project DLL (inside the BIN directory) I successfully make a call to a function and get return value. but this is just a test and when trying to access the application
7
6018
by: Geoff Jones | last post by:
Hi Could somebody give me an example of a way to call another member function of another form from a form that has been called using ShowDialog? Thanks Geoff
5
2330
by: jodyblau | last post by:
I have a form with a subform. The form has a button which opens a dialogbox. I would like the dialog box to call a sub in the subform. I know how I would do this in C++, but I can't seem to figure it out in visual basic. Is this simply a matter of changing the sub to public instead of private and then using some kind of method to execute the sub? If so, what is that method? If not, how does one go about this? Thank you,
23
5002
by: Stewart Berman | last post by:
I am trying to develop a wrapper class for the Windows API functions in Visual Studio 2008: GetOpenFileName GetSaveFileName I put together a starter class: using System; using System.Collections.Generic; using System.Linq; using System.Text;
0
9480
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10315
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10085
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9947
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7494
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6737
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5511
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4045
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2877
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.