15 мая 2023 года "Исходники.РУ" отмечают своё 23-летие!
Поздравляем всех причастных и неравнодушных с этим событием!
И огромное спасибо всем, кто был и остаётся с нами все эти годы!

Главная Форум Журнал Wiki DRKB Discuz!ML Помощь проекту


2 Questions On OCX (-Wizard)

Lior Messinger -- 100274.2607@compuserve.com
Tuesday, March 25, 1997

Environment: VC 4.2b, NT 4.0

Hi all,

I have two questions regarding code produced by the OLE Control wizard. My
control is called IMR. The wizard produces a CIMRCtrl class that represents the
controls and its members are the ones to be the methods of the IMR interface.
1. In the IMRCtrl.cpp file, the wizard puts the function:
BOOL CIMRCtrl::CIMRCtrlFactory::UpdateRegistry(BOOL bRegister)
{...}
What is this syntax (twice ::)? Is it C++? What does it mean?

2. In the DLL, I have a DDE callback function. This callback, of course, is not
a member of the CIMRCtrl class, because the a _this_ pointer would have been
passed inherently. I need to call members of the control from this callback, or
to send WM messages to the control. 
I can't define the callback with a parameter to pass the _this_ pointer, because
the DDE callback function prototype is hard-defined by Windows:
HDDEDATA CALLBACK DdeCallback(
    UINT uType,	// transaction type
    UINT uFmt,	// clipboard data format
    HCONV hconv,	// handle to the conversation
    HSZ hsz1,	// handle to a string
    HSZ hsz2,	// handle to a string
    HDDEDATA hdata,	// handle to a global memory object
    DWORD dwData1,	// transaction-specific data
    DWORD dwData2 	// transaction-specific data
   );	
 
How would I call classes in the control from this callback? Any ideas?


Thanks a lot,
Lior Messinger, 
Fundtech.




Dave Kolb -- sasdxk@wnt.sas.com
Wednesday, March 26, 1997

[Mini-digest: 6 responses]

>I have two questions regarding code produced by the OLE Control wizard. My
>control is called IMR. The wizard produces a CIMRCtrl class that represents
>the
>controls and its members are the ones to be the methods of the IMR interface.
>1. In the IMRCtrl.cpp file, the wizard puts the function:
>BOOL CIMRCtrl::CIMRCtrlFactory::UpdateRegistry(BOOL bRegister)
>{...}
>What is this syntax (twice ::)? Is it C++? What does it mean?
>[>Dave Kolb]  This is a nested C++ class.
>
>2. In the DLL, I have a DDE callback function. This callback, of course, is
>not
>a member of the CIMRCtrl class, because the a _this_ pointer would have been
>passed inherently. I need to call members of the control from this callback,
>or
>to send WM messages to the control. 
>I can't define the callback with a parameter to pass the _this_ pointer,
>because
>the DDE callback function prototype is hard-defined by Windows:
>HDDEDATA CALLBACK DdeCallback(
>    UINT uType,	// transaction type
>    UINT uFmt,	// clipboard data format
>    HCONV hconv,	// handle to the conversation
>    HSZ hsz1,	// handle to a string
>    HSZ hsz2,	// handle to a string
>    HDDEDATA hdata,	// handle to a global memory object
>    DWORD dwData1,	// transaction-specific data
>    DWORD dwData2 	// transaction-specific data
>   );	
> 
>How would I call classes in the control from this callback? Any ideas?
>[>Dave Kolb]  Use casting to convert the ptr to the proper object ptr and
>then you can use. One of the few instances where casting is warranted.
>
-----From: Gonzalo Isaza 

1) :: operator indicates in this case a member of the class.  Which
means CIMRCtrl has an internal class calles CIMRCtrlFactory which in
turn has a member function UpdateRegistry.  The :: operator is
indicating the path to the internal class.  This is similar in a way to
putting a structure within a structure and using syntax
"outerStruct.innerstruct.memberVar".

2)  There are several solutions to your problem.  One solution is to
declare a static member function in your class.  Static member functions
will not have the "this" parameter on them.  By doing this you will be
inside a control function.  Remember you don't have the "this"
parameter. 

You are asking How would I call classes in the control from this
callback? .  If what you mean is how do I call member functions in the
control, then you need to get the object from somewhere (keep a pointer
to the control object somewhere, and pick it up in your callback
somehow).  The details vary and are specific to your own application.  

I hope this helps.

Gonzalo
I speak for myself.  I don't speak for Microsoft.

> -----Original Message-----
> From:	Lior Messinger [SMTP:100274.2607@compuserve.com]
> Sent:	Tuesday, March 25, 1997 12:52 AM
> To:	MFC Mailing List
> Subject:	2 Questions On OCX (-Wizard)
> 
> Environment: VC 4.2b, NT 4.0
> 
> Hi all,
> 
> I have two questions regarding code produced by the OLE Control
> wizard. My
> control is called IMR. The wizard produces a CIMRCtrl class that
> represents the
> controls and its members are the ones to be the methods of the IMR
> interface.
> 1. In the IMRCtrl.cpp file, the wizard puts the function:
> BOOL CIMRCtrl::CIMRCtrlFactory::UpdateRegistry(BOOL bRegister)
> {...}
> What is this syntax (twice ::)? Is it C++? What does it mean?
> 
> 2. In the DLL, I have a DDE callback function. This callback, of
> course, is not
> a member of the CIMRCtrl class, because the a _this_ pointer would
> have been
> passed inherently. I need to call members of the control from this
> callback, or
> to send WM messages to the control. 
> I can't define the callback with a parameter to pass the _this_
> pointer, because
> the DDE callback function prototype is hard-defined by Windows:
> HDDEDATA CALLBACK DdeCallback(
>     UINT uType,	// transaction type
>     UINT uFmt,	// clipboard data format
>     HCONV hconv,	// handle to the conversation
>     HSZ hsz1,	// handle to a string
>     HSZ hsz2,	// handle to a string
>     HDDEDATA hdata,	// handle to a global memory object
>     DWORD dwData1,	// transaction-specific data
>     DWORD dwData2 	// transaction-specific data
>    );	
>  
> How would I call classes in the control from this callback? Any ideas?
> 
> 
> Thanks a lot,
> Lior Messinger, 
> Fundtech.
-----From: Eluri Vijaya Kumar 

At 03:51 AM 3/25/97 EST, you wrote:
>Environment: VC 4.2b, NT 4.0
>
>Hi all,
>
>I have two questions regarding code produced by the OLE Control wizard. My
>control is called IMR. The wizard produces a CIMRCtrl class that
represents the
>controls and its members are the ones to be the methods of the IMR interface.
>1. In the IMRCtrl.cpp file, the wizard puts the function:
>BOOL CIMRCtrl::CIMRCtrlFactory::UpdateRegistry(BOOL bRegister)
>{...}
>What is this syntax (twice ::)? Is it C++? What does it mean?
>

Hello,

Yes the above syntax is C++.  It is used to refer to nested classes.
So in the current case you don't see any class named "CIMRCtrlFactory" within
the class "CIMRCtrl".  But if you look in IMRCtrl.h, you will find the
statement
"DECLARE_OLECREATE_EX(CIMRCtrl)    // Class factory and guid" .
This macro expands to create "CIMRCtrlFactory" class within CIMRCtrl.
Have a look at the file \msdev\MFC\include\AFXCTL.H to understand all the
details.

bye.
Vijay

>2. In the DLL, I have a DDE callback function. This callback, of course,
is not
>a member of the CIMRCtrl class, because the a _this_ pointer would have been
>passed inherently. I need to call members of the control from this
callback, or
>to send WM messages to the control. 
>I can't define the callback with a parameter to pass the _this_ pointer,
because
>the DDE callback function prototype is hard-defined by Windows:
>HDDEDATA CALLBACK DdeCallback(
>    UINT uType,	// transaction type
>    UINT uFmt,	// clipboard data format
>    HCONV hconv,	// handle to the conversation
>    HSZ hsz1,	// handle to a string
>    HSZ hsz2,	// handle to a string
>    HDDEDATA hdata,	// handle to a global memory object
>    DWORD dwData1,	// transaction-specific data
>    DWORD dwData2 	// transaction-specific data
>   );	
> 
>How would I call classes in the control from this callback? Any ideas?
>
>
>Thanks a lot,
>Lior Messinger, 
>Fundtech.
>
>
>

-----From: sathiya@colmds2.com (Sathiyamurthy Thiruvengadathan)

Lior Messinger wrote:
> 
> Environment: VC 4.2b, NT 4.0
> 
> Hi all,
> 
> I have two questions regarding code produced by the OLE Control wizard. My
> control is called IMR. The wizard produces a CIMRCtrl class that represents the
> controls and its members are the ones to be the methods of the IMR interface.
> 1. In the IMRCtrl.cpp file, the wizard puts the function:
> BOOL CIMRCtrl::CIMRCtrlFactory::UpdateRegistry(BOOL bRegister)
> {...}
> What is this syntax (twice ::)? Is it C++? What does it mean?
> 

> 2. In the DLL, I have a DDE callback function. This callback, of course, is not
> a member of the CIMRCtrl class, because the a _this_ pointer would have been
> passed inherently. I need to call members of the control from this callback, or
> to send WM messages to the control.
> I can't define the callback with a parameter to pass the _this_ pointer, because
> the DDE callback function prototype is hard-defined by Windows:
> HDDEDATA CALLBACK DdeCallback(
>     UINT uType, // transaction type
>     UINT uFmt,  // clipboard data format
>     HCONV hconv,        // handle to the conversation
>     HSZ hsz1,   // handle to a string
>     HSZ hsz2,   // handle to a string
>     HDDEDATA hdata,     // handle to a global memory object
>     DWORD dwData1,      // transaction-specific data
>     DWORD dwData2       // transaction-specific data
>    );
> 
> How would I call classes in the control from this callback? Any ideas?
> 
I have no idea about the first question. As for the second, make the
callback function a static member function of your class. This will
avoid passing a _this_ pointer inherently.
But even from a static function you cannot access, non static data
members directly. But there are techniques described in MSDN articles,
by which you can access non-static data members from static member
functions. Check the article "Calling all members: Member functions as
Callbacks" in the MSDN (it's a pretty old article, so you should be able
to get  it in any MSDN CD). 

Good Luck,
Sathya
-----From: DFPav@aol.com

Lior:
While I am no DDE expert,  I think maybe you want to look at DdeQueryConvInfo
for part 2.
Hope it helps,
Dan
-----From: mzinner@berlin.snafu.de

> 1. In the IMRCtrl.cpp file, the wizard puts the function:
> BOOL CIMRCtrl::CIMRCtrlFactory::UpdateRegistry(BOOL bRegister)
> {...}
> What is this syntax (twice ::)? Is it C++? What does it mean?

It's a nested class, a 'class in a class'. It's just like an ordinary 
class, except it's visible only for the enclosing class. See your 
docs for 'nested class'.

> 2. In the DLL, I have a DDE callback function. This callback, of course, is not
> a member of the CIMRCtrl class, because the a _this_ pointer would have been
> passed inherently. I need to call members of the control from this callback, or
> to send WM messages to the control. 
> I can't define the callback with a parameter to pass the _this_ pointer, because
> the DDE callback function prototype is hard-defined by Windows:
> HDDEDATA CALLBACK DdeCallback(
>     UINT uType,	// transaction type
>     UINT uFmt,	// clipboard data format
>     HCONV hconv,	// handle to the conversation
>     HSZ hsz1,	// handle to a string
>     HSZ hsz2,	// handle to a string
>     HDDEDATA hdata,	// handle to a global memory object
>     DWORD dwData1,	// transaction-specific data
>     DWORD dwData2 	// transaction-specific data
>    );	
>  
> How would I call classes in the control from this callback? Any ideas?

you somehow have to  pass your _this_ pointer in one of the 
'general-purpose' 32bit parameters. I'm not shure about DDE, but what 
about passing it in dwData1 or dwData2?

-manfred



David Razzetti -- raz@jump-jet.demon.co.uk
Thursday, March 27, 1997

On 25 Mar 97 03:51:45 EST, you wrote:

>Environment: VC 4.2b, NT 4.0
>
>Hi all,
>
>I have two questions regarding code produced by the OLE Control wizard. =
My
>control is called IMR. The wizard produces a CIMRCtrl class that =
represents the
>controls and its members are the ones to be the methods of the IMR =
interface.
>1. In the IMRCtrl.cpp file, the wizard puts the function:
>BOOL CIMRCtrl::CIMRCtrlFactory::UpdateRegistry(BOOL bRegister)
>{...}
>What is this syntax (twice ::)? Is it C++? What does it mean?

Yes, its standard C++.
The UpdateRegistry method is probably static, meaning that it can be
called even when no instances of the class containing it exist.  In
order to call the method, you therefore do not need to know the name
of any object instance.  Instead, you name the class.

Example:

class Outer {
public :
...
static DoSomething() ;
};

I can call the DoSomething method at any time, using the syntax

Outer::DoSomething() ;

You see the scoping operator ( double colon ) used twice in your code
because the class CIMRCtrlFactory is nested within the CIMRCtrl class.
The class factory class is declared and defined by macros in the code
generated by the control wizard, so you probably didn't realise this.

Example:

class Outer {
public :
...
	// Nested class.....
	class Inner {
	...
	static DoSomething() ;
	};
};

In order to call the DoSomething method now, you need to competely
descope the call, as in

Outer::Inner::DoSomething() ;

>2. In the DLL, I have a DDE callback function. This callback, of course,=
 is not
>a member of the CIMRCtrl class, because the a _this_ pointer would have =
been
>passed inherently. I need to call members of the control from this =
callback, or
>to send WM messages to the control.=20
>I can't define the callback with a parameter to pass the _this_ pointer,=
 because
>the DDE callback function prototype is hard-defined by Windows:
[snip]
>How would I call classes in the control from this callback? Any ideas?

This is a fairly "standard" problem with C++.  There are several
solutions.  I suggest that you read the following article which is on
the latest MSDN CD (Jan 97).

Calling All Members : Member functions as callbacks
Dale Rogerson
Microsoft Developer Network Technology Group
April 30th, 1992

>
>
>Thanks a lot,
>Lior Messinger,=20
>Fundtech.
>




Mike Blaszczak -- mikeblas@nwlink.com
Saturday, March 29, 1997

At 22:17 3/27/97 GMT, David Razzetti wrote:
>On 25 Mar 97 03:51:45 EST, you wrote:

>>Environment: VC 4.2b, NT 4.0
>>1. In the IMRCtrl.cpp file, the wizard puts the function:
>>BOOL CIMRCtrl::CIMRCtrlFactory::UpdateRegistry(BOOL bRegister)
>>{...}
>>What is this syntax (twice ::)? Is it C++? What does it mean?

>The UpdateRegistry method is probably static,

It isn't.

>meaning that it can be
>called even when no instances of the class containing it exist. 

If it was static, that's what it would mean.  But it ain't static,
so you're barking up the wrong tree.


.B ekiM
http://www.nwlink.com/~mikeblas/
These words are my own. I do not speak on behalf of Microsoft.
       One is too many and a million is not enough.




Become an MFC-L member | Вернуться в корень Архива |