|
|
Thank you.
Tech.Support : Mam, is your pc running under windows?
Customer : No actually its close to the main door.
|
|
|
|
|
Are you referring to C++ being portable across various operating systems? If so, the answer is yes, as long as the libraries and compiler that you use are supported on the various operating systems that you want your program(s) to run on.
I hope this answers your question appropriately.
Happy Programming!
WWW::CodeProject::BNEACETP
|
|
|
|
|
I know many projects that are written under c(not c++) so that they can make it portable. but c loses the powerfull concept of OO. Does name mangaleing has any effect so that C++ code can not be make portable.
Thanx for your answer.
|
|
|
|
|
Name mangling doesnt make C++ any less portable - its the C++ code you compile, not the name-mangled output. People probably chose C for the reason that there were more C compilers in the past. Such a decision has no real bearing nowadays
|
|
|
|
|
Theorically, C/C++ are independant and run on many machines whatever the source.
Actually, if your program call some specific libraries as unistd.h (standard UNIX functions) this is not recognized by all the compilers (Visual C++ don't know unistd.h for example).
If you want to be as independant as you can, use the standard library of the language, use the native in capital lettres (as INT , UINT , BOOL )..., use TCHAR for unicode or ansi (depending on a #define ).
TOXCCT
|
|
|
|
|
I am working on a project which I am wanting to use the list class template in the C++ standard library. How would I retrieve an object from the list once it is added (in the most efficent way)?
For instance:
[...]<br />
<br />
typedef list<MyObject> ObjList;<br />
<br />
int main()<br />
{<br />
ObjList obList;<br />
MyObject* pObj = 0;<br />
<br />
for(int i = 0; i <= 5; ++i)<br />
{<br />
pObj = new MyObject();<br />
obList.push_back(*pObj);<br />
}<br />
<br />
<br />
[...]<br />
<br />
return 0;<br />
}<br />
<br />
Thanks in advance!
Happy Programming!
WWW::CodeProject::BNEACETP
|
|
|
|
|
With a list you can only move the iterator forward or backward one node at a time. So to get the 3rd node you would:
ObjList::iterator it = obList.begin();
for (int i = 0; i < 3; ++i)
++it;
MyObject *pMy3rdObject = (*it); If you need random access your objects consider using a vector instead.
Sonork 100.11743 Chicken Little
"You're obviously a superstar." - Christian Graus about me - 12 Feb '03
Within you lies the power for good - Use it!
|
|
|
|
|
I have been thinking about the possibility of using the vector<T> class as you mentioned as well. I guess I will be doing some monitored testing with both to see which one will suite my program's needs the best the most efficently. Thanks for your response.
Happy Programming!
WWW::CodeProject::BNEACETP
|
|
|
|
|
PJ Arends wrote:
MyObject *pMy3rdObject = (*it);
The above will not compile. I don't know why at the moment. Any ideas?
Below is the error given:
error C2440: 'initializing' : cannot convert from 'std::allocator<_Ty>::value_type' to 'MyObject *'
Happy Programming!
WWW::CodeProject::BNEACETP
|
|
|
|
|
Sorry, I forgot the cast
MyObject *pMy3rdObject = (MyObject *)(*it);
Sonork 100.11743 Chicken Little
"You're obviously a superstar." - Christian Graus about me - 12 Feb '03
Within you lies the power for good - Use it!
|
|
|
|
|
Hi all, here´s a "tricky" question.
let´s say i plan to use serveral threads on my app, so i write a class to wrap threads, its header could look something like this (in pseudo-code):
class CThread
{
public:
BOOL Start(); // called to create the thread
void End(); // called to terminate the thread
static DWORD WINAPI MyThreadProc(LPVOID pData); // the threadproc
};
and in my app i could create several of these at any given time, like:
void WhatEver()
{
CThread threads[5];
for(int i=0; i<5; i++)
threads[i].Start();
}
to my understanding, when a class has a static member function, one and ONLY ONE "instance" of that function´s code exsists in my application as soon as the app starts running, even if there are several instances of that class present, they all "share" the same Function code (right?)
so, there are (in the above code) 5 instances of the CThread class, but there is ONLY one instance of the MyThreadProc() function, so here´s what i dont understand, ¿what if the threads do some time consuming operation?, ¿how can threads[1] start "running" if threads[0] has´nt finished yet, and thread[2] do its stuff while thread[1] is busy and so on? or to put it in other words, if theres only one instance of MyThreadProc(), ¿how can it be used at the same time by all threads?
Thanks for reading!
|
|
|
|
|
static means different things when applied to a member function versus a member variable. static on a method means that the method does not receive a this pointer. There's no concept of "instances" for methods - the compiler generates the code for the method, and threads run that code whenever you call the method.
So you can have many threads calling the same method with no problems. (Of course, you have to protect any data from simultaneous access if necessary, but that's another topic altogether.)
--Mike--
Ericahist | CP SearchBar v2.0.2 | Homepage | 1ClickPicGrabber New v2.0.1! | RightClick-Encrypt
Kosh reminded me of some of the prima-donna programmers I've worked with. Knew everything but when you asked them a question; never gave you a straight answer.
-- Michael P. Butler in the Lounge
|
|
|
|
|
Hi Mike, and thanks for your answer, what i ment by "instances" of methods was actually a "copy" of it on memory during program execution, NE way, i know now that each thread has its own space, and there for receives its own "copy" of the function.
Thanks!
|
|
|
|
|
|
I think your confusing class instances with threads. You are correct, when you define a class function as static, there is only one copy of the function(per thread). But a thread has it's own stack. So each thread executes it's own copy of the static function. So any local variables inside the static function are multi-thread safe. But any global/static variables are not thread safe. They are shared by all threads threads.
|
|
|
|
|
Ahh! i dint know threads had its own stack, i tought they all ran in the same stack, now i understand, each thread has its own copy of the function, so there isnt "just one" copy of it.
Thanks!
|
|
|
|
|
I have an SDI app that uses an ini file to store settings. The user has the option to manually edit the ini file from my program, which is done through notepad. What I want to do is suspend execution of my program until notepad exits. I read up on createprocess() and shellexecute() along with waitforsingleobject()but couldnt figure out how to do it.
Any help would be great!
Thanks,
Daniel
|
|
|
|
|
here is some code I use to open an UDL file
and wait for the UDL Editor to exit.
BUT! Your main thread is blocked and so
the repaint is blocked!!!
<br />
SHELLEXECUTEINFO inf;<br />
memset(&inf,0,sizeof(SHELLEXECUTEINFO));<br />
inf.cbSize = sizeof(SHELLEXECUTEINFO);<br />
inf.fMask=SEE_MASK_NOCLOSEPROCESS;<br />
<br />
inf.lpVerb=_T("open");<br />
inf.lpFile=sUdlFile;<br />
<br />
if(ShellExecuteEx(&inf)) {<br />
WaitForSingleObject(inf.hProcess,-1);<br />
CloseHandle(inf.hProcess);<br />
}<br />
|
|
|
|
|
|
Original bit field: http://noisydisco.free.fr/original.jpg
Stretched bitmap: http://noisydisco.free.fr/stretched.jpg
The target bitmap init code :
BITMAPINFOHEADER bmiHeader;
ZeroMemory( &bmiHeader, sizeof(BITMAPINFOHEADER) );
bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
bmiHeader.biWidth = _dwBitmapSize.X;
bmiHeader.biHeight = _dwBitmapSize.Y;
bmiHeader.biPlanes = 1;
bmiHeader.biBitCount = 32;
bmiHeader.biCompression = BI_RGB;
_hDC = CreateCompatibleDC( NULL );
_hBitmap = CreateDIBSection( _hDC, (BITMAPINFO*) &bmiHeader,
DIB_RGB_COLORS, (void**) &_pBitmapBits, NULL, 0 );
_hOldBitmap = (HBITMAP) SelectObject( _hDC, _hBitmap );
And the stretch:
StretchDIBits( _hDC,
0, 0, _dwBitmapSize.X, _dwBitmapSize.Y,
0, 0, pbmi->bmiHeader.biWidth, pbmi->bmiHeader.biHeight,
pSource, pbmi, DIB_RGB_COLORS, SRCCOPY );
Everything seems straight forward but I can't make this work.
Where is the problem ?
Thanks for your help
|
|
|
|
|
I think you should use SetStretchBltMode(HDC hDC, int nStretchMode).
Set the mode to HALFTONE before you use StretchDIBits and look if the stretched bitmap looks better. Take a look at the MSDN library for SetStretchBltMode. I think there are some limitations if you use HALFTONE mode!
|
|
|
|
|
Hello,
I would like to handle accelerators like Ctrl+Alt+R in my dialog based app, but can't find any good source for example on doing that. If somebody have noticed somewhere an article or code snippet on doing that, please let me know,
Thanks in advance!
|
|
|
|
|
this site helped me out a lot, hope it will do the same with you
http://www4.ncsu.edu:8030/~jgbishop/codetips/dialog/accelerator_keys.html
Eugi Games
|
|
|
|
|
Thanks !
|
|
|
|