|
ch[3] = '\0';
CString strMyString = ch;
/ravi
My new year's resolution: 2048 x 1536
Home | Articles | Freeware | Music
ravib@ravib.com
|
|
|
|
|
like:
char a , b , c;
a='A';
b = 'B';
c = 'C';
CString csFullStr;
csFullStr.Format("%c%c%c", a, b, c);
The returned pointer may be temporary and should not be stored for later use.
|
|
|
|
|
i have a problem:whether different Desktop can post message to each other?
|
|
|
|
|
If they're in the same window station, I believe so.
However, I think you're talking about communications between computers, in which case you need to use some form of Remote Procedure Call.
Stability. What an interesting concept. -- Chris Maunder
|
|
|
|
|
Hi. I have a question: how can I play a mpeg movie inside a dialog box, from a SDI application?
I tried the "easy" way... and it doesn't work...
(here's the "easy" way: after creating the dialog box, and the OnSomething function, and importing CMediaPlayer, I wrote this code:
CMediaPlayer dlg;
dlg.CreateWindow (.....yadda yadda...);
dlg.ShowWindow (WS_SHOW);
dlg.m_player.Open ("Test.mpeg");
dlg.m_player.Play ();
The funny thing is.... it works fine for a dialog-based application - when I write the last 2 lines of the above code, in the OnInitInstance() function.
Any suggestion welcome. (as you can see, I'm not a great programmer, so please don't laugh )
Thanks.
We are accidents waiting to happen...
|
|
|
|
|
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.
|
|
|
|