|
It is casting the return value of GetAt() to a CEditStr* .
"The pointy end goes in the other man." - Antonio Banderas (Zorro, 1998)
|
|
|
|
|
So the GetAt functions returns a pointer of CEditStr. Perfect!
thank you everyone!!
|
|
|
|
|
If that's the case, then the cast in the code snippet you provided is redundant.
"The pointy end goes in the other man." - Antonio Banderas (Zorro, 1998)
|
|
|
|
|
So when would I use casting? How would the code snippet be redundant?
|
|
|
|
|
BrockVnm wrote:
So when would I use casting?
When an object needs to be coerced into acting like another type. Casting does not convert, is just represents.
BrockVnm wrote:
How would the code snippet be redundant?
The cast here is redundant since the array is holding CString* types and that's how we want to use it.
CArray< CString *, CString *> arr;
CString *p = (CString *) arr.GetAt(5); The cast here is necessary because the array is holding CWnd* types, but we want to use one of them as a CEdit* type
CArray< CWnd *, CWnd *> arr;
CEdit *p = (CEdit *) arr.GetAt(5); A simpler example might be:
double dRate = 1.997;
double d1 = (double) dRate;
int nWhole = (int) dRate;
"The pointy end goes in the other man." - Antonio Banderas (Zorro, 1998)
|
|
|
|
|
My oh My what a lovely answer!!!
But i guess someone has downvoted you, i will give you a 5er.
Anyways there is one thing i would like to add.
Casting has different effect on pointers and native data types.
DavidCrow wrote:
CEdit *p = (CEdit *) arr.GetAt(5);
as you said the pointer representation is modified.
and on native data types.
DavidCrow wrote:
int nWhole = (int) dRate;
is converting the data type.
MSN Messenger.
prakashnadar@msn.com
|
|
|
|
|
What's the difference between
typedef struct _MYSTRUCT {<br />
int nValue;<br />
DWORD dwValue2;<br />
}MYSTRUCT;
and
struct MYSTRUCT {<br />
int nValue;<br />
DWORD dwValue2;<br />
};
With each of them I can instantiate variables of type MYSTRUCT like:
MYSTRUCT myStruct;
And I doesn't need the old C style:
struct MYSTRUCT myStruct;
So why should I use typedef combined with struct. Are there any advantages or disadvantages.
Thanks for any comment.
Konrad
|
|
|
|
|
you're not obiged to...
the reason some code use this, it is because C don't allow to use types without the struct identifier, or when your struct is typedefed...
In C++, it is only a portability reason...
TOXCCT >>> GEII power
|
|
|
|
|
In a good old C, you can use structures only with the keyword struct . In C++, the only advantage of using typedef is, that you write the struct name with one word . In your example, MYSTRUCT is an alias to struct _MYSTRUCT .
Robert-Antonio
"Czech Railways discovered, that in case of disaster the most damaged wagons
were the first and the last. So they decided to create trains without them."
|
|
|
|
|
hi eerybody,
i am having a problem with popup menus.
The handlers associated with the menus are not called when i click on the menuitem in release mode but things work fine with debug mode.
Can anyone help.
thnx in advance,
Amit
|
|
|
|
|
in debug mode, compiler do some more operations such as setting default variable values to 0 and undefined pointers to NULL. this may cause a wrong code to be run correctly, so check your code again and look for these types of errors.
Vahid Kazemi (http://www.gameprogrammer.org)
|
|
|
|
|
i looked over but didn't get any problem of type.
|
|
|
|
|
Hi everyone,
I'm writing a program in which I need to display PDF file. I used CHtmlView class and open the PDF file so that Acrobat Reader will be automatically executed. The point here is that I want to hide the toolbar of acrobat component but cann't achieve (I tried to use DDE command but it just has effect with Acrobat Reader program but not the component inside the web page.)
Now I'm in urgent. Any suggestion is really highly appreciated !!!
Best regards.
|
|
|
|
|
Have you looked at the Acrobat SDK ?
http://partners.adobe.com/asn/acrobat/docs.jsp
the Core API may be of some help to you
-=[ QuieT Cha0s ]=-
|
|
|
|
|
hello everyone:
I have source code as the following:
Class a
{
void func2();
static void func1();
}
void a::func1()
{
AfxGetMainWnd()->PostMessage(WM_CLOSE, 0, 0);
}
void a::func2()
{
AfxGetMainWnd()->PostMessage(WM_CLOSE, 0, 0);
}
func1 is crashed, func2 is ok.
The reason is that the handler is null.
But I need to use function as static, could you tell me how to post the message from a static function?
Thank you.
-Freehawk
|
|
|
|
|
As far as the API AfxGet....it should work even in static functions also,can you explain in more detail? y exactly you need static function?
VikramS
|
|
|
|
|
Did you try that out, i belive it should work in the static function too.
MSN Messenger.
prakashnadar@msn.com
|
|
|
|
|
Where are you calling the a::func1 ? I think, that in the moment, when you call it, the MainFrame isn't yet attached to HWND (so its message handler is clearly null)
Robert-Antonio
Give a man a fish, he owes you one fish. Teach a man to fish, you give up
your monopoly on fisheries.
|
|
|
|
|
How to attach the mainFrame to HWND?
Thank you.
-Freehawk
|
|
|
|
|
Any class derived from CWnd is attached to HWND by Create or CreateEx functions.
Robert-Antonio
"A flower walked around a meadow. She saw a beatiful human and plucked off his head."
|
|
|
|
|
Thank you and other peoples very much.
I finished it.
In fact, I transfered a pointer of static function to a dll.
In the dll, the function is run.
static void func1()
{
AfxGetMainHwnd()->PostMessage(WM_MY_MSG);
// Because the func1 is run by dll, so the handle is NULL
}
so I modified it as the following :
static void func1()
{
::PostMessage(GetMainHwnd(),WM_MY_MSG,0,0);
}
GetMainHwnd() is written to save the handle of mainframe.
and it is ok.
-Freehawk.
|
|
|
|
|
As VC++.Net (2002) is unmanaged by default moeover all MFC classes (CDocumnet, CDialog etc) are unmanaged, how can I use a managed class (created in C#) within VC++.
What i am trying to do is:
1. Create a control in C#
2. Add this control in a CDialog derived Dialog in VC++.
Now, as CDialog derived class is unmanaged, I am not able to create a pointer to my managed control class. Using gcroot template class does help me over come this problme, but when i try allocating memeory by new opertaor, i get compiler error.
Do let me know how can i overcome this problem
|
|
|
|
|
There is an article under the name 'Using ADO .Net from MFC Project' that discusses this very same phenomenon. In it, the writer uses the .Net Library from an unmanaged MFC class. Although the sample uses ADO.Net, it is completely valid for all other .Net Library components as well. Even your C# control is a piece of .Net Library. The original article can be found here[^].
To implement your own control, you must compile the C# code so that it generates a DLL file. Then use the #using directive to import this DLL into your unmanaged project. You must also import the .Net Core Library (mscorlib.dll), otherwise strange behaviour might result.
When done, follow the example in the above-mentioned article starting from "__gc pointers in an Unmanaged Class" onwards for an example on how to use your control.
If you need help on creating a C# DLL, follow the guidelines in this[^] article. Then copy the finished DLL into the unmanaged project's search path and continue with the first article's instructions.
Hope this helps you out
-Antti Keskinen
----------------------------------------------
The definition of impossible is strictly dependant
on what we think is possible.
|
|
|
|
|
Dear Antii,
Thanks for the valueable information, but after i modified my code as described in the article, i come across an exception
An unhandled exception of type 'System.IO.FileNotFoundException' occurred in MFCButtonForm.exe
Additional information: File or assembly name MyControl, or one of its dependencies, was not found.
This exception occurs only when I allocate memeroy to the control pointer as
gcroot<CColoredButton*> colorButton;
#pragma push_macro("new")
#undef new
colorButton = new CColoredButton();
#pragma pop_macro("new")
Please do let me know haw can this exception be resolved.
Regards
Mohit Jain
|
|
|
|
|
Have you added the compiled C# class library DLL as a #using directive into the project ? The exception is caused by the CLR not being able to find the target assembly, and the exception is not shown unless you try to create the control.
Also, remember that after you've changed the project settings, all functions are compiled as managed by default. This means that you must add #pragma unmanaged statemets to capsulate those classes and functions that are not managed, but should be compiled as native.
I'll try to create a test project that uses a control from here in CodeProject and see what comes up. Perhaps I can then help you more, when I've seen the code in action.
-Antti Keskinen
----------------------------------------------
The definition of impossible is strictly dependant
on what we think is possible.
|
|
|
|