|
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.
|
|
|
|
|
Correction to my earlier post. The reason your application causes an assertion is because it cannot determine where the control resides. In order to solve this, use a fully qualified name of the control.
For an idea, consider if m_NetForm was a __gc wrapper for type System::Windows::Forms* and would then be instantated as a form object by calling m_NetForm = new System::Windows::Forms();
Does this solve the issue ?
I tried to create a simple example application. It uses the .Net Framework 1.1 to create a file writer object (StreamWriter) and writes a single line into the file. You can download the sources and a working executable from here[^]. The text file is created into the same directory from which the application is ran.
-Antti Keskinen
----------------------------------------------
The definition of impossible is strictly dependant
on what we think is possible.
|
|
|
|
|
Thanks for your suggestions and the sample. Besides your suggested approach, I had to copy my Control's dll to the folder from where my MFC app was running in order to resolve the exception.
Thanks again.
Regards
|
|
|
|
|
GETTEXTEX myVals;
GETTEXTLENGTHEX myLen;
myLen.flags = GTL_DEFAULT;
myLen.codepage = 1200;
myVals.cb = 2 + SendMessage(hWnd, EM_GETTEXTLENGTHEX, (long)&myLen, 0);
myVals.flags = GT_DEFAULT;
myVals.codepage = 1200;
myVals.lpDefaultChar = NULL;
myVals.lpUsedDefChar = NULL;
wchar_t *buf = new wchar_t[myVals.cb];
if(SendMessage(hWnd, EM_GETTEXTEX, (long)&myVals, (long)buf))
{
return buf;
}
This piece of code gets the text from a rich edit window as intended. But it seems to work only for richedits in my window. If hWnd is a handle to a richedit in another applications window, say WordPad, then the application (WordPad) gives an error and quits.
What am I doing wrong?
|
|
|
|
|
Hey buddy, you can't expect the data from other applications with just sendmessge. The other application as it's own process area.You may get integet like data using such messges but not the text lie stuff
You have to insert yourself into other application to make such work.See Window Hooks....
|
|
|
|
|
I'm trying to make a small skinning util to use with a current project. To do this i want to use binary region files created by an external tool based on a bitmap. Now what i want to do is be able to load the region data from a file, instead of having to load via a resource, which adds a lot of bulk to the executable, as well as doesnt allow for dynamic skinning. If can think of a fairly easy/reasonable method of doing this, please respond. Thank you
|
|
|
|
|
You can store the skining information in either .ini file (recommended) or xml file (todays standard)
MSN Messenger.
prakashnadar@msn.com
|
|
|
|
|
Thats what i was planning on doing, but i dont know how to load the actual binary data from the .rgn file to the HRGN structure
|
|
|
|
|
hello everyone:
I want to post a message to the main frame of singledocument window, how to do?
I made as the following :
((CMainFrame*)AfxGetMainWnd())->PostMessage(WM_MY_MESSAGE, 0, 0);
but the program is crashed.
I dont know why?
Thank you.
-Freehawk
|
|
|
|
|
do u have a handler set up for the message?
if so is the problem there?
sending a message is hardly likely to crash an app (unless of course its that famous microsoft vb message WM_CRASH)
"there is no spoon" biz stuff about me
|
|
|
|
|
Thank you for the reply.
I think you are right.
but I dont know how to set up the handler.
Could you help me?
-Freehawk
|
|
|
|
|
l a u r e n wrote:
microsoft vb message WM_CRASH
can we simulate it in VC++??
MSN Messenger.
prakashnadar@msn.com
|
|
|
|
|
Hi,
If any one give me the sample MFC code to Read / Write / Append and print those Registry value of type REG_MULTI_SZ.
I would like to append the names with the existing values of type REG_MULTI_SZ.
Thanks in Advance
irams
|
|
|
|
|
For a Win32 API command, use RegQueryValueEx , and as the fifth parameter, a pointer to a _large_ char-buffer. Then put the size of the char buffer in the sixth parameter.
You can create an oversized buffer to accommondate for a large amount of REG_MULTI_SZ data types. This data resides in the registry as follows:
1. A string
2. A NULL character
3. A string
4. A NULL character
5. A string
.
.
.
n. Two NULL characters
If you want to copy these values into a set of CString objects, you need to implement a parsing function yourself that reads the returned buffer and creates CString objects dynamically, finally returning a pointer into the first occurence, and perhaps the amount of CString objects created.
Unfortunately no example code available at this point.
-Antti Keskinen
----------------------------------------------
The definition of impossible is strictly dependant
on what we think is possible.
|
|
|
|
|
CRegKey class will do all the reading and writing of the registry.
MSN Messenger.
prakashnadar@msn.com
|
|
|
|
|
Dear friends,
I need to develop a packet sniffer program. For this purpose i need to place my adapter in "promicious mode".
Can you tell me how can i programitically place the adapter in "promicious mode". ????
Imtiaz
|
|
|
|
|
Can anybody please tell me what is this error?and how
to rectify it?
fatal error: cannot open program database vc60.pdb
|
|
|
|
|
When do you get there, Is there any other error before you get this error.
MSN Messenger.
prakashnadar@msn.com
|
|
|
|