|
OnInitInstance is related to the application thread... there i guess it would have any effect.
humm as far i have understood this could be the solution..
Create an sdi application with form view and then place the mov player and do the coding for it like a normal dialog application in the view.
MSN Messenger.
prakashnadar@msn.com
"If history isn't good, just burn it." - Sidhuism.
|
|
|
|
|
Hi all,
this is the error I'm getting:
"error C2276: '&' : illegal operation on bound member function expression",
Apparently, this is due to assigning a pointer to a virtual function, yet I do not have any function declared virtual. Does any one know a way around this problem? Is there a way to force a function not to be virtual? Here's a snippet of my code:
In .h
…
class MyClass
{…
int VBGCalc(const gsl_vector *x, void *params, gsl_vector *f, gsl_matrix *J);
int VBGPartials(const gsl_vector *x, void *params, gsl_matrix *J);
int VBGFunct(const gsl_vector *x, void *params, gsl_vector *f);
int VBGF(void); //problem in this function
…
};
in .cpp
int MyClass::VBGF(void)
…
f.f = &VBGFunct; //offending code
f.df = &VBGPartials; //ditto
f.fdf = &VBGCalc; //ditto
…
return 1;
}
int (* f) (const gsl_vector * x, void * params, gsl_vector * f);
gsl_vector and gsl_matrix are struct variables.
Thanks,
Ralf.
ralf.riedel@usm.edu
|
|
|
|
|
You can't assign a member function pointer to an ordinary function pointer. The type of VBGFunct is int (MyClass::*) (const gsl_vector *, void *, gsl_vector *) . You can't take the address of a member function pointer.
You would have to either declare f as int (MyClass::*f)( /*etc*/ ) or declare your functions as static . If you do the first, you must call them using the ->* or .* notation, e.g.:
(this->*f)(pX, pParams, pF) If you do the second, you won't be able to access any non-static members of MyClass .
If you're trying to provide polymorphism, it's easier to either do run-time polymorphism via inheritance, or compile-time polymorphism using templates.
Stability. What an interesting concept. -- Chris Maunder
|
|
|
|
|
member functions are of __THISCALL so i guess assigning a pointer to the method could of some problem and also using it..
try making the methods static i guess then it will work... But then i dont know wheather making them static is in ur software design.
MSN Messenger.
prakashnadar@msn.com
"If history isn't good, just burn it." - Sidhuism.
|
|
|
|
|
Made it static. Much easier. Thank you all,
Ralf.
ralf.riedel@usm.edu
|
|
|
|
|
Hi,
How can I add something to a listbox, AFTER it's initialized?
First, I use this code:
BOOL CDialog1::OnInitDialog()
{
CDialog::OnInitDialog();
m_ListBox.AddString("jef");
return true ;
}
and this works fine. But I want to be able to add other items afterwards (to be precise, I would like to be able to show the user which webcams are available.)
So I made a function:
void CCamDialog::AddListBox()
{
m_ListBox->AddString("camera");
}
But this gives an error (debg assertion failed).
any ideas?
thanks
|
|
|
|
|
When is AddListBox() getting called? If it is before the listbox window actually exists, you obviously cannot add to it.
"The pointy end goes in the other man." - Antonio Banderas (Zorro, 1998)
|
|
|
|
|
You are trying to do 2 different things.
BOOL CDialog1::OnInitDialog()
m_ListBox.AddString("jef");
This list box belongs to CDialog1.
void CCamDialog::AddListBox()
{
m_ListBox->AddString("camera");
}
This listbox belongs to CCamDialog.
As I understand what you are trying to do, you are trying to add "camera" to the same listbox as "jef". Unless you have a pointer to the CDialog1::m_Listbox in the CCamDialog, you are trying to add "camera" to a listbox that may or may not exist. My guess is that CCamDialog::m_Listbox doesn't exists and that will give you a assertion failure.
Artificial intelligence is no match for natural
stupidity.
|
|
|
|
|
Sorry for that, Guess I copied it wrong (I was trying to make it work in an other application)
It should be
BOOL CDialog1::OnInitDialog()
{
CDialog::OnInitDialog();
m_ListBox.AddString("jef");
return true ;
}
and
void CDialog1::AddListBox()
{
m_ListBox.AddString("camera");
}
|
|
|
|
|
Okay. Now I have 2 questions. Where is the AddListBox function being called from? and what is the assertion failure that you are getting?
Artificial intelligence is no match for natural
stupidity.
|
|
|
|
|
Addlistbox is being called like this:
void CDialogTestApp::OnTest1()
{
CDialog1 d1;
d1.AddListBox();
d1.DoModal();
}
(with ontest1 being an eventhandler when i press a menuitem)
The Failure isn't much of a help (well, not for me...) , It only says Debug Assertion Failure, and when I press "retry", it gives another error, "unhandled exception at 0x7c25bec6(mfc70d.dll) in DialogTest.exe: User Breakpoint"
thanks for your help btw! It's very much appreciated...
|
|
|
|
|
I found a way (well somebody told me a way ) to do it.
I just added a stringarray to my Dialog, which I could fill before the Initialization, and then I could just add the items in the string to my listbox.
Thanks for helping me!
|
|
|
|
|
Qualvis wrote:
void CDialogTestApp::OnTest1()
{
CDialog1 d1;
d1.AddListBox();
d1.DoModal();
}
I believe that would be your problem. You are instantiating the dialog but then trying to add things to a control that doesn't exist yet.
Artificial intelligence is no match for natural
stupidity.
|
|
|
|
|
Hello
I have in my app. print button. My app. must print in "landscape" mode
only, because there are some long tables to print.
Could someone tell me how to set up this option (page orientation) programatically? Or some tips. Anything will do
thank you
Chris
|
|
|
|
|
If its an MFC app, it will have an DEVMODE object which is a member of your CWinApp class. Call these functions and pass throught the required page orientation
bool SetPrintOrientation(HANDLE &hDevMode, int mode) const
{
if (hDevMode == INVALID_HANDLE_VALUE)
return false ;
switch (mode)
{
case DMORIENT_PORTRAIT :
{
LPDEVMODE pDevMode = (LPDEVMODE)::GlobalLock(hDevMode) ;
pDevMode->dmOrientation = DMORIENT_PORTRAIT ;
::GlobalUnlock(hDevMode) ;
}
break ;
case DMORIENT_LANDSCAPE :
{
LPDEVMODE pDevMode = (LPDEVMODE)::GlobalLock(hDevMode) ;
pDevMode->dmOrientation = DMORIENT_LANDSCAPE ;
::GlobalUnlock(hDevMode) ;
}
break ;
default :
ASSERT(FALSE) ;
return false ;
}
return true ;
}
int GetPrintOrientation(HANDLE &hDevMode)
{
int val = DMORIENT_PORTRAIT ;
if (hDevMode != INVALID_HANDLE_VALUE && hDevMode != NULL)
{
LPDEVMODE pDevMode = (LPDEVMODE)::GlobalLock(hDevMode) ;
val = pDevMode->dmOrientation ;
::GlobalUnlock(hDevMode) ;
}
return val ;
}
Roger Allen - Sonork 100.10016
Strong Sad:
Clever I am? Next to no one.
Undiscovered and soggy.
Look up. Look down. They're around.
Probably laughing. Still, bright, watery.
Listed among the top. Ten.
Nine. Late night. Early morn.
Early mourn. Now I sleep.
|
|
|
|
|
thanks. it looks good. And Yes it Is MFC application but there is a problem.
i tried it on:
protected:
HGLOBAL m_hDevMode;
member of CWinApp
and in pInfo->m_pPD->m_pd.hDevMode in CPrintInfo.
And the problem is that this variables are always 0 and i have an exception
in SetPrintOrientation(..) function
Can you give me some more tips?
thanks in advance
-- added later ---
ok i found solution
i must call GetPrinterDeviceDefaults(..) first
|
|
|
|
|
OK, I think I might know what the answer to this is going to be, put I'll post my problem anyway, as you never know, there may be a simpler solution...
I have a service app that listems for incoming socket connections using good old Berkeley style socket code - I have code that creates the socket to listen on and then a thread that uses "select" to wait for the connections, spawning a new thread per-connection to handle the data, e.g.:
<br />
for ( ; ; )<br />
{<br />
...<br />
fd_set read;<br />
FD_ZERO(&read);<br />
FD_SET(m_hSocket, &read);<br />
int nResult = ::select(-1, &read, NULL, NULL, &tv);<br />
if (nResult == 1)<br />
{<br />
SOCKET s = ::accept(read.fd_array[i], NULL, NULL);<br />
AfxBeginThread(...);<br />
}<br />
}<br />
The problem is that if I hammer the app using a test program that creates lots of simultaneous connections to the server (using a separate thread for each all started at once), before long some of these connections will fail with WSAECONNREFUSED. This seems to be because creating the thread to handle the accepted socket in the code above is expensive in terms of CPU and the incoming connections piling up whilst I am doing this are causing the backlog (5 sockets?) to be exceeded.
I *think* the answer will be to use IO completion ports but this is going to be a big job. The threads I create to process each socket are short-lived, and I know IOCP can ensure fewer are needed but will it also help with this backlog problem or is there another more generic way to handle this? At some point in the distant future I may want to port the code to Linux (yikes!) so I wanted to avoif anything MS specific.
Comments?
The Rob Blog
|
|
|
|
|
Why spawn a thread *AFTER* a connection attempt? Prepare a pool of worker threads all waiting on a single semaphore would be the easiest fix I believe(least effort on your part)... after all, triggering a single semaphore event should cost a fraction of AfxBeginThread(...)
try Recycle all threads instead of respawn... and dont harm any animals.
-Dan
|
|
|
|
|
Cheers for the tip - I will investigate further...
The Rob Blog
|
|
|
|
|
First, you should be able to set the backlog value to much higher than 5. This will ease most problems immediatley. You've not shown the listen section so I will assume you've used a large value.
Second, you could split the code into two threads:
Thread 1 sits waiting for new connections, accepts them, and puts the socket handle into a queue. Thats all it does - it then immediatley resumes accepting other connections. Thread 2 sits on the queue, and creates a thread for each socket.This detachs the (slow) thread creation process from the (fast) accept process, and you should be able to pretty much reach the maximum accept rate you can.
|
|
|
|
|
Using winsock2, the maximum backlog value is apparently now 0x7fffffff (SOMAXCONN) but I tried this without any success. I will experiment with new values.
I also tried two threads as you suggested, using a shared array of SOCKETs - the accept thread adds the accepted socket to the list and then signals the second thread via a semaphore, but still I had problems. I used a critical section to protect the shared socket array, but perhaps I need to revisit this.
Thanks for the advice - switching to IOCP and AcceptEx is a major task that itself looks fraught with problems if my search of Google Groups is anything to go by!
The Rob Blog
|
|
|
|
|
I have a framework that does IOCP/AcceptEx/System Thread Pool stuff for Windows based network servers. It's (n)ill documented at present but you can take a look here.
The intent is to be able to support multiple listening sockets on multiple adaptors using multiple network protocols (primarily IPv4 and IPv6 I suppose) and exploit the Windows good stuff for networking.
The idea was to impose a minimum of dependency between the server framework and the rest of the application, you have to provide a 'per connection' class that must implement a minimal interface, but after that it's up to you. No inheritance required, namespaces are used so that my idea of a CRITICAL_SECTION wrapper doesn't collide with yours, etc etc.
I believe it would be possible to construct a framework for Unix type systems that would be compatible with such a 'per connection' class and be reasonably efficient in that environment. Time will tell.
Paul
|
|
|
|
|
I want to do the following in a seperate app:
WindowFromPoint() using mouse location, and then read the DC of that window into a BMP of some sort, the only way I can see it to create a transparent window on top of the window I have just "spied".
At the end of the day, I want to read the location of a rectangle drawn into the DC of the "spied" upon window. I then want to create a edit control in the same size as the rectangle underneath it. The last bit is easy, it's how to even try to read the DC/bitmap of another window I have no clue how to do.
Any clues.;)
Conrad B
Always do badly to start off, that way when you get the hang of it suddenly, everyone is surprised.
|
|
|
|
|
Hi, I want to create a GUI for a C program and I don't know where to start! I've never used Visual C++ before,can anybody give me any help???
Cheers.
|
|
|
|
|
in Visual C++, use the Win32 Application wizard (File->New Project or such) and let it create a simple Win32 program for you... you can see how the fundamental ideas in win32 apps work (window messages, the message loop, creating windows, registering window classes)
r -€
|
|
|
|