|
I have a function that performs some drawing according to the bitdepth of the screen. The function is called in a loop continuously. The problem is, after a while it crashes. I have narrowed it down the problem to the HDC not being released. How can i release it?
void Plot()
{
//Obtain current screen depth
HDC hdc = ::GetDC(NULL);
int screendepth=GetDeviceCaps(hdc, BITSPIXEL);
//do something here according to the current bitdepth
//how to release here?
}
|
|
|
|
|
From the MSDN documentation on the GetDC function
After painting with a common DC, the ReleaseDC function must be called to release the DC. Class and private DCs do
not have to be released. ReleaseDC must be called from the same thread that called GetDC. The number of DCs is
limited only by available memory.
"You're obviously a superstar." - Christian Graus about me - 12 Feb '03
"Obviously ??? You're definitely a superstar!!!" mYkel - 21 Jun '04
Within you lies the power for good - Use it!
|
|
|
|
|
The following code below is from a text on numerical recipes in C++...Its purpose is to evaluate the integral of a function, "func", using the Gaussian Quadrature formula, viz:
<br />
double qgaus(double func, double a, double b)<br />
{<br />
double xr,xm,dx,s;
double x[] = {0.1488743389816312,0.4333953941292472,<br />
0.6794095682990244,0.8650633666889845,0.9739065285171717};<br />
double w[] = {0.2955242247147529,0.2692667193099963,<br />
0.2190863625159821,0.1494513491505806,0.0666713443086881};<br />
<br />
xm = 0.5*(b+a);<br />
xr = 0.5*(b-a);<br />
s = 0;<br />
<br />
for(int j=0;j<5;j++)<br />
{<br />
dx = xr*x[j];<br />
s += w[j]*(func(xm+dx)+func(xm-dx));<br />
}<br />
return s *= xr;<br />
}
Im trying to adapt the code to integrate my function, "func", which returns an array of values, viz:
<br />
void function(double (*func)[nSize],CKuchukDlg *pDialog)<br />
{<br />
enum{nSize = 100};<br />
double Ip[nSize],p[nSize],gh[1][nSize];<br />
double alpha[nSize],beta[nSize];
<br />
for(int t=0;t<nSize;t++)<br />
{<br />
if(t==0)<br />
{<br />
alpha[0] = beta[0] = 1;<br />
p[0] = sqrt(pow(alpha[0],2.0)+pow(beta[0],2.0));<br />
<br />
homo(gh,nSize,pDialog);<br />
Integrals(Ip,nSize);<br />
<br />
func[0][0] = (gh[0][0] * Ip[0])/p[0];<br />
}<br />
else<br />
{<br />
alpha[t] = beta[t] = 2*t*PI;<br />
<br />
homo(gh,nSize,pDialog);<br />
Integrals(Ip,nSize);<br />
<br />
p[t] = sqrt(pow(alpha[t],2.0)+pow(beta[t],2.0));<br />
<br />
func[0][t] = (gh[0][t] * Ip[t])/p[t];<br />
}<br />
}<br />
}<br />
Can anyone please show me how I may do this? I have tried a number of ways, but I keep running into errors. Thank you!
|
|
|
|
|
I need to refer something on C++ and found this
#include <iostream>
using namespace std;
int main()
{
int foo = 4;
int bar = 16;
// ptr - non-constant pointer, non-constant data
//
int* ptr = &foo;
*ptr = 6; // OK: Data is non-constant, so it can be
// changed via ptr
ptr = &bar; // The pointer is non-constant, so it may
*ptr = 22; // point to other data And change it
// ptr_to_const - non-constant pointer, constant data
//
const int* ptr_to_const = &foo;
return 0;
}
When i read this
const int* ptr_to_const = &foo;
Non constant pointer to constant data ;
But foo isnt declared as constant .
Why does the compiler not warn me of this ?
|
|
|
|
|
|
A pointer to constant data needs to be initialized, that's what this line does, and no specification says the "initializer" must be constant. Using pointers to constant data is in essence declaring an intention not to modify that data, nothing more. Sure, if you try to modify it, no warning will be shown - it'll be an Error!
The other possible case is declaring a constant pointer. You certainly can initialize it, but not make it point anywhere else afterwards.
|
|
|
|
|
Because prt_to_const is a promise that you won't modify the data through ptr_to_const, not that the data it points to cannot change by other means!
One good reason to use const is to force other code to not change something. A class might return a ptr_to_const, that points to private internal class data. The class itself might modify the data via some function call latter, but it would be a mistake to let anything other than the class modify that internal data.
|
|
|
|
|
Hi Everyone
I have a DLL which should later monitor a specified app. But how can I notify my Main Program that something has change ?
starts Routine
-----------------------------
|
\/ ^
|------| |----------------|
| DLL | | Main Program |
|------| |----------------|
| ^
| |
--------------------------
should notify the program if something changes
So i thought about a callback function, but i don't know how i can realize this
Please help ???
MFG
RedDragon2kx
Unix and C are the ultimate computer viruses.
Visit me: www.programming.info.ms
|
|
|
|
|
maybe in your dll you need to have an function that you can call that will check your app. Pass a message to the app and have the app send a message back with it's status.
I guess you need to ask your self.
1. How is this dll going to be loaded. From another application or your main app?
2. What is it that you are monitoring. Whether the main app is still running?
3. What is the purpose of the dll? Will it tell me something about the main app that will make it (the dll) do something else?
4. Is the main app something you wrote or someone else wrote?
Tom Wright
tawright915@yahoo.com
|
|
|
|
|
So I have 3 Apps:
The first App is the MainApp which loads the DLL
The second "App" is the DLL which montiors the third App
The third App is some app which gets monitored by the DLL
While all apps are still running the DLL monitors the third App. And when the third App for e.g. calls WM_PAINT the Main App should get notified by the DLL.
Unix and C are the ultimate computer viruses.
Visit me: www.programming.info.ms
|
|
|
|
|
Much clearer. What you want to do is create a hook in your dll, so that you can monitor any messages that are being sent to that app. There are a ton of articles on window hooks.
Tom Wright
tawright915@yahoo.com
|
|
|
|
|
Any interprocess communication technique will do. I would recommend using a memory-mapped file or thread messages, but that's up to you. For a list of effective IPC mechanisms refer to J.Richter's "Programming Windows", it's worth reading anyway.
|
|
|
|
|
I'm having a problem passing a structure with WM_COPYDATA. Can anyone give an example of how to do this on the sending side an the receiving side?
Thanks
Tom Wright
tawright915@yahoo.com
|
|
|
|
|
How are you currently doing it? Are you passing the address of your struct in the lpData member of the COPYDATASTRUCT?
"You're obviously a superstar." - Christian Graus about me - 12 Feb '03
"Obviously ??? You're definitely a superstar!!!" mYkel - 21 Jun '04
Within you lies the power for good - Use it!
|
|
|
|
|
yes. Here is my function that send the message from a thread I created:
<br />
typedef struct tagCONNSTATUS {<br />
int nConnID;<br />
CString sThreadID;<br />
CString sConnStatus;<br />
}CONNSTATUS;<br />
CONNSTATUS ConnStatus;<br />
<br />
ConnStatus.nConnID = ConnID;<br />
ConnStatus.sThreadID = thdID;<br />
ConnStatus.sConnStatus = "Connected";<br />
<br />
COPYDATASTRUCT myData;<br />
myData.dwData = 0;<br />
myData.cbData = sizeof(ConnStatus);<br />
myData.lpData = &ConnStatus;<br />
<br />
<br />
if (!SendMessage(myHandle->m_hWnd, WM_COPYDATA, 0, (LPARAM)&myData))<br />
MessageBox(NULL, "Error Posting Connection Message", "Error on PostMessage", MB_OK | MB_ICONEXCLAMATION);<br />
<br />
Here is the function that receives the message in my main application:
<br />
BOOL CLAMsgSwDlg::OnCopyData(CWnd* pWnd, COPYDATASTRUCT* pCopyDataStruct)<br />
{<br />
typedef struct tagCONNSTATUS {<br />
int nConnID;<br />
CString sThreadID;<br />
CString sConnStatus;<br />
}CONNSTATUS;<br />
<br />
(DWORD)((CONNSTATUS*)(pCopyDataStruct->lpData))->nConnID;<br />
(LPCSTR)((CONNSTATUS*)(pCopyDataStruct->lpData))->sThreadID;<br />
(LPCSTR)((CONNSTATUS*)(pCopyDataStruct->lpData))->sConnStatus;<br />
<br />
CONNSTATUS ConnStatus;<br />
AfxMessageBox(ConnStatus.sConnStatus);<br />
AfxMessageBox(ConnStatus.sThreadID);<br />
<br />
return 1;<br />
}<br />
<br />
When my message boxes pop up they show nothing.
Tom Wright
tawright915@yahoo.com
|
|
|
|
|
Tom Wright wrote:
typedef struct tagCONNSTATUS {
int nConnID;
CString sThreadID;
CString sConnStatus;
}CONNSTATUS;
CONNSTATUS ConnStatus;
AFAIK the problem is with the CString s. They contain pointers to the actual string data, and you can not pass pointers across process boundaries as the pointers will have no meaning to the recieving process.
You have to build your structure in such a way that it does not contain any pointers. For example:
typedef struct tagCONNSTATUS {
int nConnID;
TCHAR sThreadID[128];
TCHAR sConnStatus[128];
} CONNSTATUS;
"You're obviously a superstar." - Christian Graus about me - 12 Feb '03
"Obviously ??? You're definitely a superstar!!!" mYkel - 21 Jun '04
Within you lies the power for good - Use it!
|
|
|
|
|
Yeah I'm still getting nothing. I've tried it where I'm passing a test string from a CString object and that worked. However I cannot get a structure to pass coreectly. Not sure what I have set wrong.
Thanks for the help anyway. I'll keep plugging a long.
Tom Wright
tawright915@yahoo.com
|
|
|
|
|
The concept is not difficult. All it does is copy cbData bytes from the memory at lpData .
If you want to see a working example, take a look at http://www.codeproject.com/tools/imageviewer.asp[^]. The sending code is in the ViewerDll project; ImageView function. The receiving code is in the ViewerApp project; OnCopyData function.
I am willing to provide more help if you need it, just ask.
"You're obviously a superstar." - Christian Graus about me - 12 Feb '03
"Obviously ??? You're definitely a superstar!!!" mYkel - 21 Jun '04
Within you lies the power for good - Use it!
|
|
|
|
|
I figured it out. I needed to do a memcpy on the receving side. Once I did that I was able to receive all the data in my struct.
<br />
typedef struct tagCONNSTATUS {<br />
int nConnID;<br />
TCHAR sThreadID[128];<br />
TCHAR sConnStatus[128];<br />
}CONNSTATUS;<br />
<br />
CONNSTATUS ConnStatus;<br />
memcpy(&ConnStatus, pCopyDataStruct->lpData, sizeof(ConnStatus));<br />
m_lClientConn.SetItemText(ConnStatus.nConnID, 3, ConnStatus.sConnStatus);<br />
Thanks for the help.
Tom Wright
tawright915@yahoo.com
|
|
|
|
|
I'm trying to insert a status bar control inside a the activex window in OnCreate. It only appears if i resize the window, also how can i change it from being indented(Pushed In) i would like it closer to what the Mainframe window looks like.
Thanks
|
|
|
|
|
Maybe I'm totally wrong here but wouldn't it be better off to create your status bar in the OnInitdialog()?
I'm confused are you trying to create and activex control that has a MDI window in it, and you want a status bar on the child windows? Or are you creating an activex control with a dialog window in it and are placing it in a MDI app, and you want a status bar in the dailog box / activex control?
Tom Wright
tawright915@yahoo.com
|
|
|
|
|
Rather than creating CStatusBar in OnCreate function Better to Create OnPaint Function .. I hope it will work .. becos every time u resize or any changes on window it calls to onpaint function..
|
|
|
|
|
Hello,
I was wondering if there is any other way of setting the text in a static control to bold - except constructing my own font?
Thanks!
|
|
|
|
|
in resource editor, you can change the font of the entire controls in a dialog.
Ninety-eight percent of the thrill comes from knowing that the thing you designed works, and works almost the way you expected it would. If that happens, part of you is in that machine.
|
|
|
|
|
Well,
the problem is that I don't want to change the font for the entire dialog but for that specific static control
Thanks for the help anyway
|
|
|
|