|
Llasus wrote: I was adviced last time to do that. Please refer to this link[^].
I am also confused seeing that.
AFAIK, it cannot be shared.
From MSDN:
"GDI objects support only one handle per object. Handles to GDI objects are private to a process. That is, only the process that created the GDI object can use the object handle"
The GDI handles are actually offset to the handle map's that reside in the client side. So when you pass a handle to another process, it simply points to a location in the handle table in that process. Some times, the object in that location will be entirly a different one such as Brush or Pen or some times the object itself is not created. So the result will be unpredictable.
if you want to know more please read the article Give Me a Handle, and I'll Show You an Object[^]
|
|
|
|
|
Naveen wrote: I am also confused seeing that. [Confused]
Guess I trusted that advice too early, even though I had a doubt in my mind if it was possible in the first place.
Anyway, I'll read the article to have more knowledge on this and try coding the solution that you gave me earlier on. Thank you very much for your help and time! 
|
|
|
|
|
Sorry for the advice man but i was really not aware of the fact that handles cant be shared across the processes.
Regards,
Sandip.
|
|
|
|
|
Hi Sandip. its ok. you helped me out not to do the clipboard solution anyway. Thank you. 
|
|
|
|
|
Hi Naveen,
Thanks for the information.
Regards,
Sandip.
|
|
|
|
|
|
|
Hamid. wrote: Why you dont use of WM_COPYDATA?Inter-Process Communication using WM_COPYDATA[^].
Thank you for the suggestion. I am looking into it right now but the size of the bitmap bits actually is not a constant value. So I'll be needing a pointer for that in which WM_COPYDATA can't be used. I'm still checking some other routes like named pipes, or shared memory. Any further suggestions? Thank you!
|
|
|
|
|
hi
i have aquestion i really need an answer for it because it frustrated me...
look at these two functions:
void CSecondDlg::OnButton1()
{
FILE *fp;
FILE *file1 = fopen("file1.txt","w");
int nFileLong;
char strFilter[] = { "CPP Files (*.cpp)|*.cpp|All Files (*.*)|*.*||" };
CFileDialog m_ldFile(TRUE, ".cpp", NULL, 0, strFilter);
if (m_ldFile.DoModal() == IDOK)
{
m_sFileName=m_ldFile.GetPathName();
fp=fopen(m_sFileName,"rb");
fseek(fp,0,SEEK_END);
nFileLong=ftell(fp);
char* sText = new char[nFileLong+1];
fseek(fp,0,SEEK_SET);
int i=fread(sText,1,nFileLong,fp);
sText[i]=0;
m_EDIT1=sText;
fprintf(file1,"%s\n",m_EDIT1);
fclose(file1);
fclose(fp);
UpdateData(FALSE);
}
}
AND
void CSecondDlg::OnButton2()
{
FILE *fp;
FILE *file2 = fopen("file2.txt","w");
int nFileLong;
char strFilter[] = { "CPP Files (*.cpp)|*.cpp|All Files (*.*)|*.*||" };
CFileDialog m_ldFile(TRUE, ".cpp", NULL, 0, strFilter);
if (m_ldFile.DoModal() == IDOK)
{
m_sFileName=m_ldFile.GetPathName();
fp=fopen(m_sFileName,"rb");
fseek(fp,0,SEEK_END);
nFileLong=ftell(fp);
char* sText = new char[nFileLong+1];
fseek(fp,0,SEEK_SET);
int i=fread(sText,1,nFileLong,fp);
sText[i]=0;
m_EDIT2=sText;
fprintf(file2,"%s\n",m_EDIT2);
fclose(fp);
fclose(file2);
UpdateData(FALSE);
}
}
as u can see the two functions do the same thing :
open afile into an edit box ....then save the content of the edit box in another file (.txt)
what is bizzare??
well if i open browse1 and browse2 button ...i would find that the first file is created and the second not...(because i hit the button browse1 first).
if i try another time but with hitting browse2 first the opposite thing happend (the second file is changed but not the first )
what is wrong ????
i reaaaly dont know what to do ??
please help me with this
my project stopes on this....
thank u all
|
|
|
|
|
I can't seem to find the difference between two functions. Can you step through your program and see what exactly is going on?
-Saurabh
modified on Monday, June 23, 2008 2:07 AM
|
|
|
|
|
thanks for ur reply
but my application is simple ...two edit controls each with its "browse" button.
first load afile to edit .....then store the content of the edit to ".txt" file...
its that simple....
if u try it for the first time ...it works for both ...
but in second and third and .....etc times....the odd problem occures
??????????
what is it that i did wrong
please would u try it urself and help me understand and solve the problem
my project stop on this
thank u
|
|
|
|
|
It doesn't matter that application is simple or complex. Point is you have a bug in your application that means there is a problem some where. So as I suggested why don't you try to step through your program and check whats going on. Another idea is just create a new application and copy this code over because the code you provided works fine for me.
-Saurabh
|
|
|
|
|
Well your code (though a bit weird: duplication) works on my system.
BTW why don't you delete the allocated memory?
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
how????
did u tried it multiple times...
and in both way worked???
please i really need to know whats wrong...
|
|
|
|
|
Yes it actually works.
I've made three tests:
(1) Button1 followed by Button2 (loaded two different files)
(2) Button2 followed by Button1 (loaded two different files)
(3) Button1 followed by Button2 (loaded the same file)
All of them were OK.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
ok...
what version of vc r u using>>>>>iam using 6
someone else tried it also and it didnot work out
|
|
|
|
|
Are you kidding?
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
no iam not .... iam serious
whats wrong???? 
|
|
|
|
|
Well, I'll try also on VS6 . Maybe this evening (here I've only VS2005 ).
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
I'm not real familiar with code on the heap, but the statement
char* sText = new char[nFileLong+1]; //reserve string space
is created with "new". Doesn't that require a "delete" or equivalent (I don't know the syntax) to de-allocate that space? If you don't then that space can't get re-allocated since the pointer is lost when you exit the procedure. Don't know what kinds of problems could occur as a result.
|
|
|
|
|
One problem your code has is in the method you are opening the files with fopen. There are two modes for reading and writing to files - binary mode and text mode. Some character conversions change in those two modes. When you open file1 and file2 you do not specify what mode to use, so the default mode is used. When you open m_sFileName you tell it to open it to read in binary mode instead of text mode.
Try changing the "w" to "wt" in this statement of yours
FILE *file1 = fopen("file1.txt","w");
And more importantly change the "rb" to "rt" since you are trying to read characters in the following statement in your code
fp=fopen(m_sFileName,"rb"); //Open file for reading
The ftell and fseek functions may not give the correct lengths if the file is opened in text mode, however. So you should simplify things and use the fgets() function to get the string you want.
Since you are working with text files they should be opened with the text attribute.
modified on Tuesday, June 24, 2008 6:30 AM
|
|
|
|
|
i created following code.
template <typename t>
class c{
public:
int f1(){ fp=f1; return 1;};
char* f2(){ fp=f2; return "hi";};
t recentFunction(){ return fp(); }
private
t (*fp)();
}
is it validity?
i wanna get a code for recentFunction
i do not know how to implement compounding funtion point and template
pleae help me 
|
|
|
|
|
Try something like this.
template <typename t> class c
{
public:
typedef t (c::*FuncPtr)();
int f1()
{
mFp=&c::f1;
return 1;
}
char* f2()
{
mFp=&c::f2;
return "hi";
}
t recentFunction()
{
return (this->*mFp)();
}
private:
FuncPtr mFp;
};
Test it using this.
c<int> c1;
c<char*> c2;
c1.f1();
int x = c1.recentFunction();
c2.f2();
char* ret = c2.recentFunction();
If you want to read more about member function pointer search for delegates. There are numerous articles on this topic on codeproject. One of them is Member Function Pointers and the Fastest Possible C++ Delegates[^].
-Saurabh
|
|
|
|
|
This question is difficult to ask. The concept is simple, but the details of explaining it just go on and on.
Using Visual Studio 2008, I have created an application with MFC. In this application there is to be a linked list of instantiated objects. This list is to live the lifetime of the program and be publically accessible.
Not being familiar at all with the windows concept, where do I instantiate/create this object? There is no place within the code that VS created that I recognize as being something that can hold a permanent variable.
If the question is clear at this point, you might want to stop reading now. I am confused so the remainder of this post may be even more confusing.
The base class that VS created is listed below. Where should I insert something like:
CMyClass myinstance = new( CMyClass );
Or maybe:
CMyClass myinstance;
I want that because in another class I wish to write:
CMyClass::myinstance.LinkNewItem( new_item );
Hopefully this will cause a new item to be linked in to the linked list and other code can traverse the list to work with the data.
It none of this is appropriate, please advise as to what is appropriate.
Here is the cpp file that VS created. Where does my code belong?:
// test1.cpp : Defines the class behaviors for the application.
//
#include "stdafx.h"
#include "test1.h"
#include "test1Dlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#endif
// Ctest1App
BEGIN_MESSAGE_MAP(Ctest1App, CWinApp)
ON_COMMAND(ID_HELP, &CWinApp::OnHelp)
END_MESSAGE_MAP()
// Ctest1App construction
Ctest1App::Ctest1App()
{
// TODO: add construction code here,
// Place all significant initialization in InitInstance
}
// The one and only Ctest1App object
Ctest1App theApp;
// Ctest1App initialization
BOOL Ctest1App::InitInstance()
{
// InitCommonControlsEx() is required on Windows XP if an application
// manifest specifies use of ComCtl32.dll version 6 or later to enable
// visual styles. Otherwise, any window creation will fail.
INITCOMMONCONTROLSEX InitCtrls;
InitCtrls.dwSize = sizeof(InitCtrls);
// Set this to include all the common control classes you want to use
// in your application.
InitCtrls.dwICC = ICC_WIN95_CLASSES;
InitCommonControlsEx(&InitCtrls);
CWinApp::InitInstance();
AfxEnableControlContainer();
// Standard initialization
// If you are not using these features and wish to reduce the size
// of your final executable, you should remove from the following
// the specific initialization routines you do not need
// Change the registry key under which our settings are stored
// TODO: You should modify this string to be something appropriate
// such as the name of your company or organization
SetRegistryKey(_T("Local AppWizard-Generated Applications"));
Ctest1Dlg dlg;
m_pMainWnd = &dlg;
INT_PTR nResponse = dlg.DoModal();
if (nResponse == IDOK)
{
// TODO: Place code here to handle when the dialog is
// dismissed with OK
}
else if (nResponse == IDCANCEL)
{
// TODO: Place code here to handle when the dialog is
// dismissed with Cancel
}
// Since the dialog has been closed, return FALSE so that we exit the
// application, rather than start the application's message pump.
return FALSE;
}
Thanks for your time
|
|
|
|
|
It seems you are creating a dialog based application. In that case you can put your data in the dialog class. In the example code you provided in the Ctest1Dlg which should be in the files test1Dlg.h and test1Dlg.cpp.
-Saurabh
|
|
|
|