A change from 2002 to 2005 wrt to global templatized operators?
We just upgraded from a quite old VC++ to 2005. In the process, something
has stopped working that seems like it's completely legal. Basically we have
our own very large framework. We have the usual streaming classes (base
classes for in and out streams, from which various specific streaming
classes are derived for files, memory, etc...) and the usual
templatized collection classes. We want our collections to be streamable,
where the instantiation element supports it, so we provide the usual global
(friend) streaming operators with each collection type, so that
streamability isn't forced on the instantiation element types, something
like:
//
// A templatized collection class with friend declarations for
// the streaming operators
//
template <class T> class TFundStack : public TObject
{
public :
.......
protected :
friend TBinOutStream& operator<<
(
TBinOutStream& strmOut
, const TFundStack<T>& fcolToStream
);
friend TBinInStream& operator>>
(
TBinInStream& strmIn
, TFundStack<T>& fcolToStream
);
}
// In the same header, global streaming operators
template <class T> TBinInStream&
operator>>(TBinInStream& strmToReadFrom, TFundStack<T>& colToStream)
{
}
template <class T> TBinOutStream&
operator<<(TBinOutStream& strmToWriteTo, const TFundStack<T>& colToStream)
{
}
* TBinInStream and TBinOutStream are the base classes from which various
types of binary in/out streams are derived.
// In a test app, I'd create a stack, put something in it
TFundStack<tCIDLib::TCard4> fcolStack(4);
fcolStack.Push(1);
// Then create an memory based output stream and stream the stack
TBinMBufOutStream strmTestOut(8192, 8192);
strmTest << fcolStack << kCIDLib::FlushIt;
The compiler doesn't find the global operators and I get an unresolved
symbol error on operator<<(TBinOutStream&, TFundStack<tCIDLib::TCard4>), so
it's not making the connection from the streaming of the stack to the
provided global streaming operator.
Is there something I'm missing here? Is this no longer valid in C++ or is
this some quirk of VC++ 2005, or is there some new switch I need or some
such thing?
-------------------------------------
Dean Roddey
Chairman/CTO, Charmed Quark Systems
www.charmedquark.com Tag: searching for a file Tag: 269316
graphics.h
hi all,
i'm trying to build a program with graphics but its not possible in
visual c only in borland
what is the option for use graphics in visual c? Tag: searching for a file Tag: 269315
ShellExecute thows First-chance exception
Hello,
i have a small app with some ShellExecutes.
for example this one:
ShellExecute(hWnd, "open", "http://www.domain.com", NULL, NULL,
SW_SHOWNORMAL);
Everytime i debug my app and this command is executed, the debuger will
output the following:
First-chance exception at 0x7c812a5b in explorer.exe: Microsoft C++
exception: CError at memory location 0x00fce708..
i also tried ShellExecute(NULL, NULL, ...).
What's the reason for this simple shellexecute and why is a First-chance
exception thown here? Tag: searching for a file Tag: 269306
Quick basic C question!
Hello,
I am reviewing some C code when I have come across the following piece of
code, please take a look:
/////////////////////////////////////////////////////////////
void main()
{
int hour;
display_bcd(hour);
}
void display_bcd( byte n)
{
putc(n/16+'0');
putc(n%16)+'0');
///////////////////////////////////////////////////////////////////////////////
Regarding the second line of code of the display_bcd function, If I
understand right, say n = 10, so,
10%16 = 10 + (ascii value of 0, which is 48) sent through putc we get
the following character ":" right?
However I don't understand the first line: putc(n/16+'0'); ???
Why is he dividing a byte value by 16?
What happens to a byte value when divide by a number anyways?
I looked around in a few C books but could not find any samples resembling
this.
All feedback sincerely appreciated!
Thanks
--
Best regards
Robert Tag: searching for a file Tag: 269303
opengl so slow with large meshes
Hi,
I use opengl to draw surfaces. I use
glBegin(GL_POLYGON) ,..... and use it to draw meshes in the order of 2000 *
2000.
But it goes very slow when my arrays are in this order.
Is there any way to speed it up ?
Thanks a lot,
Behzad Tag: searching for a file Tag: 269296
want to see trace of programe execution on text file .
While debugging on vc .net we can see stack trace . I want this stack
trace to be written on
a text file . Is this kind of facility provided by vc .net ? If yes
what setting i need to do ?
Regards ,
Mangesh Sawant . Tag: searching for a file Tag: 269290
some headers seems to conflict the others
Hi everybody,
I have a sort of strange problem, I need to search for a special file
(perl.exe) in run time and searching the help I have found out
CFileFind but it needs afx.h to be included. The problem is when I
include afx.h some other parts of my program which were being built and
working properly seem impossible to be built. an example is
Directory::GetCurrentDirectory(). I had a similar problem with
including windows.h. again some formerly proper statements seemed to
turned out to unproper ones after including windows.h and
Directory::GetCurrentDirectory() was one of them. The error message in
both cases are the same and seem even stranger to me. It is :" error
C2039: 'GetCurrentDirectoryA' : is not a member of
'System::IO::Directory' " I don't have any GetCurrentDirectoryA. what
the problem could be? Tag: searching for a file Tag: 269286
Visual C++ 6.0
Hello all,
We have a client that needs an update to an old Visual C++ 6.0
application. One of our developers has tried to get it working in
VS.NET 2005 but he says he's having troubles with the DLLs and linking.
We have a current MSDN Professional subscription, but we do not see
Visual C++ 6 on there, only 4.x and below. Is there any way we can get
the 6.0 version?
Thanks,
Craig Tag: searching for a file Tag: 269274
rs232...
Hello Scott and everyone else who will read this post.
After many messages that I posted on the news groups about rs232, I have
come up with functional code which reads in as many as 25 characters in one
operation, meaning that a micro-controller can send 25 bytes to the PC and
VC++ has no problem reading this. The code can be altered to read many more
bytes than 25 if required, however I only tested up to 25. All you need to do
is to change the first defined statement > BYTESTOREAD!
Scott, I have learnt a lot form our exchage of posts, so I figure I would
like to share with you, what I have come up with, and I would appreciate your
opinion â?¦ However, I know that the code can probably be made more efficient,
however I think, for me, for now, its quite okay!
This is not the way I will leave the code, there will be some final touches
such as better placement of #define statements and so forth!
I will put comments under every line of code, so if you disagree with the
commentary feel free to correct it.
//////////////////////////////////////////////////////////////////////
#include <windows.h>
CSerialWnd MySerial;
//Create an object of Cserial type.
LRESULT CALLBACK WndProc_CW1 (HWND hwnd, UINT message,
WPARAM wParam, LPARAM lParam)
{
//RS232 *Receive mode
#define BYTESTOREAD 25 //Depicts the amount of bytes to read!
#define OB_BYTES ((BYTESTOREAD*2)+1) //Number of bytes for official Buffer !
static DWORD dwBytesRead;
//Declaration of variable to indicate actual bytes that are
//read in within the time limit that windows allowed!
static byte CatchByte_BUFFER[BYTESTOREAD+1];
//Bytes returned from the MySerial.Read() function, will be
//immediatelly assigned to this array.
static byte Accum_BUFFER[BYTESTOREAD+1];
//Since windows cannot assure a constant amount of bytes
//returned from the MySerial.Read() function(which come
// from the rs232 port), then when CatchByteBUFFER
//is full, I transfer its bytes to the Accum_BUFFER. So
//now, CatchByteBUFFER is ready for another, set of bytes
//returned from the next MySerial.Read() function.
static TCHAR Official_BUFFER[OB_BYTES];
//This array holds the final and complete string that was read
in .
int k,n,j;
//General purpose variables used to loop and index arrays
//RS232 SERIAL PORT MONITOR
if (message == CSerialWnd::mg_nDefaultComMsg)
{
const CSerialWnd::EEvent eEvent = SerialWnd::EEvent(LOWORD(wParam));
const CSerialWnd::EError eError = CSerialWnd::EError(HIWORD(wParam));
switch (eEvent)
{
case CSerialWnd::EEventRecv:
// A serial message occurred
j = 0;
//Holds Accumulative array index value
do
{
MySerial.Read(CatchByte_BUFFER,
sizeof(CatchByte_BUFFER),
&dwBytesRead);
//Read the port, and the third parameter
//will hold the amount of bytes read in!
CatchByte_BUFFER[dwBytesRead] = '\0';
//Null Terminate the CatchByte_BUFFER array!
n = dwBytesRead;
//Re-assign the amount of bytes read in to another
variableâ?¦
//The reason for this was that I would get the
following error, if I
//were to put this variable straight into the for
loop command:
//c:\_DTS_PROGRAMMING\C_PROGRAMMING\vc++\MY_APPS_LAB
// \XPPLC\WndProc_CW1.cpp(220) : warning C4018: '<' :
//signed/unsigned mismatch.
//So for now, I just re-assigned it!
for(k=0;k<n;k++)
{
Accum_BUFFER[k+j] = CatchByte_BUFFER[k];
//Store the bytes that were just read in into an
//accummulator array!
}
j = j + dwBytesRead;
//Advance the index for the Accum_BUFFER array
//so we can append the next bytes which reside in the
//CatchByte_BUFFER array in the next iteration!
}
while(j != (BYTESTOREAD) && j != 0);
//If all the bytes were read in, then , j will
be equal to
//BYTESTOREAD and will break out of the while
loop, and
//also, for unneccessary subsequent port reads
where
//dwBytesRead will equal to 0, meaning that no
bytes were
//read, then this will cause the breaking out
//of the while loop aswell!
MultiByteToWideChar(CP_ACP,0, (LPCSTR)Accum_BUFFER,-1,Official_BUFFER,OB_BYTES);
//Finally, assign the fully accumulated bytes
//to a TCHAR string array, which are
converted
//to unicode, if I am not mistaken!
break;
default:
break;
}
return 0;
}
switch(message)
{
case WM_CREATE:
MySerial.Open(TEXT("COM1"),hwnd,WM_NULL,lParam,0,0);
//Open the rs232 port
MySerial.Setup(CSerial::EBaud9600,CSerial::EData8,
CSerial::EParNone,CSerial::EStop1);
//Set up the rs232 port
return 0;
case WM_CLOSE:
MySerial.Close(); //Close Port!
break;
return 0;
}
return DefWindowProc(hwnd, message,wParam,lParam);
}
/////////////////////////////////////////////////////////////////////////////////////////////
The above code has been extensively tested, many times and has never failed.
After spending many hours on the subject, I thought I could shine some light
on rs232 in a laymens kind of way, I know for many of you, this is probably
unworthy of your time or knowledge, however, if I would of have had this type
of post 3 months ago, it really would of made the rs232 implementation curve
a lot simpler for me! I invite anyone that is a beginer and finds rs232
complicated just as I did, (and still do! Because I am sure there is much
more to this) to use it and improve upon it!
I have one question though! What is the advantage of using the Wndserial
class as opposed to using functions like CreateFile, WriteFile, ReadFile, and
CloseHandle.
Would I be better off, or is it because in Windows it would be too
complicated!
Just asking!
I thank Scott and all members of the news groups that have helped me on the
subject!
You guys, are a great resource on the subjects of C,C++,VC++.
--
Best regards
Robert Tag: searching for a file Tag: 269260
WTL and winbase.h
Hi, I'm using Microsoft Visual C++ 2005 Standard, I recently downloaded
the latest version of WTL, and used it's AppWiz to create a simple
application. Upon compiling, however, I'm met with nearly 200 errors,
most of which look something like this:
c:\program files\microsoft visual studio
8\vc\platformsdk\include\winbase.h(226) : error C2146: syntax error :
missing ';' before identifier 'Internal'
c:\program files\microsoft visual studio
8\vc\platformsdk\include\winbase.h(226) : error C4430: missing type
specifier - int assumed. Note: C++ does not support default-int
c:\program files\microsoft visual studio
8\vc\platformsdk\include\winbase.h(227) : error C2146: syntax error :
missing ';' before identifier 'InternalHigh'
c:\program files\microsoft visual studio
8\vc\platformsdk\include\winbase.h(295) : error C2146: syntax error :
missing ';' before identifier 'CRITICAL_SECTION'
c:\program files\microsoft platform sdk\include\winbase.h(307) : error
C2146: syntax error : missing ';' before identifier 'PVOID'
c:\program files\microsoft platform sdk\include\winbase.h(315) : error
C2086: 'int DECLSPEC_IMPORT' : redefinition
c:\program files\microsoft platform sdk\include\winbase.h(2031) : error
C2146: syntax error : missing ';' before identifier 'ullTotalPhys'
And so on and so forth. Incidently, these errors also occur when I try
to compile other applications and frameworks dependent on the PSDK,
such as wxWidgets. I've already tried downloading a fresh SDK and point
VC++ towards it.
Can anyone help me figure out what's wrong here?
Thanks. Tag: searching for a file Tag: 269258
cin and binary mode
Is there any chance of slightest light at the end of the tunnel in pursuing
the cin and binary mode operation together?
I am trying to see if I can open the cin in binary mode for read operation.
I am using VC++ with VS .NET 2003
While using VS 6.0, it was a piece of cake, but since there were a lot of
things just removed in VC++ .NET 2003 version, I am having a hard time
converting this little piece of code....
previously with VS 6.0 it was,
istream_withassign myFile;
filebuf *myFileBuf;
.......
myFileBuf = new filebuf (_fileno(stdin));
myFileBuf->setmode(filebuf::binary);
myFile = myFileBuf; // stream object is stream buffer
if (!(myFile.read(data, nBytes)))
{
if (myFile.eof())
{
status = M_EndOfFile;
}
else
.....
}
Which worked just fine.
Any ideas or hopes of converting it to VC++ .net 2003?
I have done something like this.... which obviously does not work..... It
reads the EOF before I expect it to. And it may be something with the cin not
opened in binary mode.
std::istream* myFile;
..........
myFile = &std::cin;
if (!(myFile->read (reinterpret_cast<char*>(data), nBytes)))
{
if (myFile->eof())
{
status = M_EndOfFile;
}
else
..........
}
Any help is appreciated..... Thanks in advance,
M Tag: searching for a file Tag: 269254
comparing a "wchar_t" to "char"
So I want to compare the longer wchar_t type to a char type, using
wcsstr and wcsstr.
With a raw string, I can use 'L' like so:
wcsstr((uint16_t *)wchar_String, L"regularCharString")
BUT... say I have:
char * reg = "regularCharString"
How would I call wcsstr using the reg variable? (Tried typecasting,
but that doesn't work.) Tag: searching for a file Tag: 269249
Excluding NAN entries when summing an array
Hi all, what is a safe and efficient way to sum the contents of an array
or a matrix, skipping any possible NANs or INFs?
Thanks,
RS Tag: searching for a file Tag: 269236
How to create a console while running MFC
Hi,
I want to show some information of an application.
Anyone knows how to dump a console while the major MFC application is
running?
Thanks in advance
Jack Tag: searching for a file Tag: 269229
rs232? Again....
Hello,
I have had success doing rs232 where my cpu can read from my PC. I am now
trying to get my PC to read from my cpu. I had success on this also, 2 months
ago at reading 8 bytes into the PC end. Everything was fine, however, today I
had the uncontrollable urge to try to read 9 bytes!!!!!! Well guess what?
back to the drawing board I am!
:-)
I want to ask a very simple question and go step by step! Because I though I
understood what I was doing 2 months ago after extensive research on the
subject, but I am obviously wrong!
On my cpu end, I am sending a string like this:
///////////////////////////////////////////////////////////////
char RS232_1_ExtOut[] = "ABCDEFGH";
for(i=0;i<7;i++)
fputc(RS232_1_ExtOut[i],COM_1);
/////////////////////////////////////////////////////////////
As you can guess, this sends a string of eight characters out on com 1 of
the cpu!
Now, on the PC side (VC++) I have:
///////////////////////////////////////////////////////////////////
static DWORD dwBytesRead = 8;
static BYTE abBuffer[9];
int TEMP;
MySerial.Read(abBuffer,sizeof(abBuffer),&dwBytesRead);
TEMP++;
//////////////////////////////////////////////////////////////////
Okay, I have a break point on the "TEMP++;" line!
For starters, ain't I supposed to read 8 bytes max, hence the variable
dwBytesRead?
And, abBuffer has enough room to hold the total amount of bytes read plus a
null termination character. Right!
So why, at this particular moment at breakpoint time! , abBuffer contains,
"ABCDEFGÃ?Ã?"
2 Months ago when I got this to work, in the cpu code, I used to send a null
character "\0" after my string. I stopped doing this, because I realized it
didin't have any effect.
I have been told before by news groups fellows that rs232 returns many
bytes, but isn't the purpose of the:
MySerial.Read(abBuffer,sizeof(abBuffer),&dwBytesRead);
function, supposed to limit the amount of bytes read to the value passed in
the 3rd parameter?
All suggestions and help is very appreciated!
P.S. Does anyone know where I can get documentation describing all of the
Serial class.... I tried to ask this to the author, but got no response!!!
--
Best regards
Robert Tag: searching for a file Tag: 269220
read from an istream object
Hi,
This is what I am trying to do - If the filename is given I have to read
from the file else I have to read from cin. The program below compiles fine
but while reading from cin, it reads some part of the stream fine but
encounters an EOF prematuerly. If I read from the cin in a file I see the
full data. So I know that cin does get all the data, just that the read
function behaves in an unexpected way.
std::istream* myFile; // stream object to read the cin
std::filebuf* myFileBuf; // specifies a streamBuffer
.......
if (!myFileName)
{
myFile = &std::cin;
}
else
{
myFileBuf = new std::filebuf;
if (!(myFileBuf->open (myFileName, std::ios::in | std::ios::binary)))
{
status = My_FileOpenErr;
}
else
{
myFile = new std::istream (myFileBuf);
}
}
.........
Then I have the read function
if (!(myFile->read (reinterpret_cast<char*>(mydata), nBytes)))
{
if (myFile->eof())
{
status = My_EndOfFile;
}
else
{
status = My_IOErr;
}
}
Please help,
Thanks in advance.
M Tag: searching for a file Tag: 269211
Application design for shared data repository programmed in VC on Win32
Hello folks,
This might be slightly offtopic but not very much so ,since the
development is to be done in VC for Win32 environment.
I have a requirement whereby there is an in-memory data repository
which should be housed in a certain binary module .
The access to this in-memory data repository is only through an API
exposed by the same binary module.The operations allowable are the
creation of new record , deletion of record , update of record, and
record search.
Moreoever this binary module should provide this API to any application
on the same machine and simultaneous access ( protected by some
synchronization primitive for data integrity ofcourse ) is also
allowable.
Now i have a couple of ideas on how to implement this on Win32 ,but
would also like to hear about any advice or suggestions that you might
have.
One of the ideas i am thinking of is along these lines. The binary in
which the data repository is housed ,should be a DLL , with exported
functions that provide the API for data access.
Any application which wants to use the data repository ,would load the
DLL in its address space. There should be exactly one copy of the data
( let us say for the sake of discussion for the time being , in a
statically allocated array of structures ) for as many applications
that have loaded the DLL. The data structure would be a global in the
dll.
-The memory is typically owned by the any process that loads the dll ,
so how do we make it sure that this data structure has memory which is
common to as many processes that have loaded the DLL.
How does this type of design sound , i would really appreciate any
comments and suggestions on this. Or any related best practices.
thanks in advance.
regards
Taha Tag: searching for a file Tag: 269205
behaviour of simple short -> int conversion differs in debug and release version
The following code prints out -1 in debug mode (correct) and 0 in
release mode (wrong) if compiled with Visual Studio.NET 2003.
#include "stdafx.h"
int _tmain(int argc, _TCHAR* argv[])
{
short usVal;
// enter -1
std::cin >> usVal;
int iVal = usVal;
iVal = iVal >> 17;
std::cout << iVal << std::endl;
return 0;
} Tag: searching for a file Tag: 269201
VC++ 6 vs. VC++ express: please advise
I'm planning to write some code for a friend (for free), and may use C++,
which I haven't used in 5 years. Just installed my VC++6 on Windows xp home
edition.
Since my recollection of MS VC++ has faded anyway, I was thinking of trying
their free VC++ express (I love C++ but never gave MS VC++6 high marks for
user friendliness). I have some questions and reservations, and would
appreciate any advice.
--Will installing the free VC++ express mess up my installation of VC++6,
somehow making that less usable?
I imagine installing VC express might answer the remaining questions, but
I'm a bit afraid to do that without reassurance about its effect on VC++6.
--does VC express have the full ISO C++, including STL?
--are there restrictions, like amount of memory used, size of arrays, etc?
--does it produce reasonably fast code?
--is it easy to get started?
--what else does VC express lack that the full commercial product has?
--any other comments are welcome
My code is not going to be polished professional work--just a favor for one
friend. But I do need STL, operator overloading, reasonable speed of
execution, and to be able to read/write text files on disk and display info
to the user. Basically, the program is going to read *a lot* of data, do
some *lengthy* numerical number crunching, write some results back to disk,
and display some results.
Thank you all! Tag: searching for a file Tag: 269189
What the L? in wsprintf
Hi,
I'm programming in Visual C++ 2005 Express Edition and am having a problem
with wsprintf. I'm trying to display a variable value on screen, here is my
code:
wsprintf(pelement->string, L"%d", (UINT32)val);
Only the most significant character shows up. L"%2d" or L"%3d" doesn't
really help. If I use just "%3d" without the L it just displays %3d on the
screen. Text works fine with the line:
wsprintf(pelement->string, L"%s", "test");
Others I have talked to don't even use the L, so why do I seem to need it.
Why does it not display integers correctly? And what does it mean?
Thomas Tag: searching for a file Tag: 269180
Strange delete memory failure
Hello all,
I have the following problem:
i am declaring something like that:
char* mystring = new char[200];
then i'm filling the string. After lloking the memory, it looks like it
is correct with 4 no man's land bytes before and after the string and
correct length.
However, when deleting (delete [] mystring), it causes a debug assertion
failure even if just before the delete, my string is still well defined
in memory.
How can such a thing happen? I know I am doing a lot of processing
between declaration and delete and that could be that i am writing at
the wrong adress but this is not the case here.
What should I check in this case?
thanks for any help.
bye
F. Tag: searching for a file Tag: 269178
dllexport and DEF files!!
OK I'm writing a dll in C (can't use C++), and I was using the
_declspec(dllexport) to export the functions, however it crashed when
making calls because I didn't have a DEF file.
Now I understand you only need a DEF file if you don't use
_declspec(dllexport) or if you're using _stdcall calling convention,
which I'm not.
Is this just a C requirement, and not needed in C++? Tag: searching for a file Tag: 269170
Cannot link with library
Hello All,
I am writing one dll which gets statically linked to some lib say
library1.lib.
library1.lib exports some functions say function1. After building
library1.lib,I have linked to it by going
project->settings->linker->input. I have used some functions from it in
my DLL.
Now when I build DLL, it gives me some linker errors like
ssleay32.lib(s2_srvr.obj) : error LNK2019: unresolved external symbol
__imp__SetLastError@4 referenced in function _ssl2_accept
ssleay32.lib(ssl_cert.obj) : error LNK2019: unresolved external symbol
__imp__GetLastError@0 referenced in function
_SSL_add_dir_cert_subjects_to_stack
ssleay32.lib(ssl_lib.obj) : error LNK2019: unresolved external symbol
_time referenced in function _ssl_update_cache
like wise
Could someone shed some light on this problem ?
Thanks. Tag: searching for a file Tag: 269168
HELP: DLL and synchronizing global data
I have a DLL that contains global data. The data is initialized from DllMain
during DLL_PROCESS_ATTACH and destroyed during DLL_PROCESS_DETACH. Once
initialized, the global data is only read from and not modified at all.
My question is what sort of protection should I provide, if any, to this
global data. I have done some testing and everything appears to work with no
synchronization at all, my concern is that problems might appear when
running on multiprocessor machines, something I can't test for at the
moment.
Any help much appreciated...
--
Best regards
Mark Tag: searching for a file Tag: 269161
COMDAT folding - which flags disable it inadvertently?
Howdy;
I'm wondering which compiler flags in VC++ 2003 and 2005 would inadvertently
disable COMDAT folding?
Reading one of Raymond Chen's blog posts, /Za definitely kills COMDAT
folding support.
The reason I ask is because we're replacing some old non-templated arrays
with templated array types in one of our larger projects, and we're getting
a huge increase in size via a Release build with the relevant
COMDAT-specific flags turned on.
Also: can COMDAT folding occur cross-library? Or is that only possible if
Whole Program Optimization and Global Optimizations are turned on?
Thanks!
Si Tag: searching for a file Tag: 269160
Run in debug mode with VS and Without. Difference?
Here is my problem whihc is very strange for me;
(VC++ 2003)
i am developping a multi-threaded DLL and using STL of VC++,
(especially "list")...
So far i always compiled my code in debug mode... ok...
Here it is;
When i run my application with double click on it, it throws a run-time
error; i search and i found that it gives error on a "delete xStruct;"
statement,
i commented it and it again gave an error when trying to run push_back
of STL list.
Here is the strange thing;
Without changing "anything" instead of double clicking&running the app.
when
i start it via "Start" button (again in debug mode) in VS 2003 it works
perfect...
How can u explain it??? Tag: searching for a file Tag: 269159
VC BUG,SO BIG
class c{
int i_;
public:
c(int i){
printf("c\r\n"); i_ = i;
}
~c(){
printf("~c\r\n"); i_ = -1;
}
void foo() const{
printf("foo,%d", i_);
}
};
class a{
public:
const c & c_;
a() : c_( c(1) )
{
}
};
int main()
{
a _1;
_1.c_.foo();
}
The ~c() will never invoke.
So RAII is a dream. Tag: searching for a file Tag: 269153
defragmenting memory
I got a shareware program that supposedly defragments memory in
Windows.
Any ideas what kind of VC++ functions it is probably using? Tag: searching for a file Tag: 269150
GetProcAddress() refused to return address
I'm trying to explicitly link a 3rd party DLL, but I can't get
GetProcAddress() to return an address to any of my functions. I'm able
to link implicitly, and here's a declaration for one of the functions
that I used for implicit linking:
extern "C" int __declspec(dllexport) __cdecl OpenFile(LPCTSTR
AFileName);
That works when linking implicitly. So when linking explicitly,
LoadLibrary() returns fine, but when I call:
GetProcAddress(hDLL, "OpenFile");
it returns NULL and GetLastError() indicates "The specified procedure
could not be found". I've Googled for this, but this seems to be a very
unique problem, and I don't know what else to try.
I'm running VC++8.0. Tag: searching for a file Tag: 269148
Profiling code with optimisation on
Hi,
I have some templated vector code to unroll a loop, see below. I am
trying to test this code against a simple a*a + b*b + c*c vector dot
product to see if it truly is producing the same code. I ran the code
below and had a look at the assembly listing and it does look like the
inlining works, but unfortunatly the optimising power of the compiler is
so great that it substituted my code for a simple:
int main()
{
printf("%f", 14.0f);
return 0;
}
which is great, but not what i want for profiling purposes :-). I still
want some optimisation for inlining the code, just not so much. NOTE: I
only have the basic optimise for speed settings, nothing fancy like
global intrinsic functions....
template<typename _Value>
struct Vector
{
_Value _value;
};
template<typename _Vector> struct VectorDotProd {};
template<typename _Type, int _Length>
struct VectorDotProd<Vector<_Type[_Length]> >
{
typedef Vector<_Type[_Length]> _Vector;
__inline static float Apply(_Vector const & vector0,
_Vector const & vector1)
{
return Impl<_Type, _Length-1>::Apply(vector0, vector1);
}
template<typename _Type, int _Index>
struct Impl
{
__inline static float Apply(_Vector const & vector0,
_Vector const & vector1)
{
return vector0._value[_Index] * vector1._value[_Index]
+ Impl<_Type, _Index-1>::Apply(vector0, vector1);
}
};
template<typename _Type>
struct Impl<_Type, 0>
{
__inline static float Apply(_Vector const & vector0,
_Vector const & vector1)
{
return vector0._value[0] * vector1._value[0];
}
};
};
int main()
{
typedef Vector<float[3]> Vector3f;
Vector3f v0 = {1.0f, 2.0f, 3.0f};
Vector3f v1 = {1.0f, 2.0f, 3.0f};
float result = VectorDotProd<Vector3f>::Apply(v0, v1);
_RPTF1(_CRT_WARN, "v0.v1 = %f\n", result);
printf("%f\n", result);
return 0;
} Tag: searching for a file Tag: 269147
Deploying builds, PDB, C7 and debug symbols...
Is there a way to ship debug symbols linked into the PE with MSVC8?
It seems only the PDB method is supported because of the linker, yet the
C++ compiler knows how to embed C7 in the .obj files.
It is very tedious for us to deploy .PDB with each .DLL and .EXE,
through Subversion, because of the sheer size of these...
Does somebody have a solution to this problem?
Cheers,
Bertrand Tag: searching for a file Tag: 269144
Tooltip only shown sometimes?!
Hello,
I implemented a simple tooltip for my deskband which is only shown
sometimes. for example after activating the deskband and hover over the
band, the tootip is shown. it is not shown, when the time of the tooltip
is eleapsed (smoothed out) and i hover the cursor again over the band.
it is also not shown when i click on the desktop and then hover the
cursor over the band.
..sounds difficult?! :-) to understand what i mean, have a look at the
tooltips of the tray icons. they are shown always.
has anyone an idea what's happening here? i looked at the msdn lib, used
google, but all without success.
thanks for any tips and advices!
//////////////////////////////////////////////////////////////////////
m_hWndToolInfo = CreateWindowEx(
WS_EX_TOOLWINDOW,
TOOLTIPS_CLASS,
NULL,
WS_POPUP | TTS_NOPREFIX,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
m_hWnd, // Window Handle of Deskband
NULL,
g_hInst, // Instance of Deskband
NULL);
if (m_hWndToolInfo)
{
SetWindowPos(m_hWndToolInfo,
HWND_TOPMOST,
0, 0, 0, 0,
SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE | SWP_SHOWWINDOW);
char strTT[400] = "Some Text";
LPTSTR lptstr = strTT;
// Initialize Members of the Toolinfo Structure
m_ti.cbSize = sizeof(TOOLINFO);
m_ti.uFlags = TTF_SUBCLASS | TTF_IDISHWND;
m_ti.hwnd = m_hWnd;
m_ti.hinst = g_hInst;
m_ti.uId = (UINT)m_hWnd;
m_ti.lpszText = strTT;
// Send an TTM_ADDTOOL to the Tooltip Control
SendMessage(m_hWndToolInfo, TTM_ADDTOOL, 0, (LPARAM) (LPTOOLINFO) &m_ti);
SendMessage(m_hWndToolInfo, TTM_ACTIVATE, true, 0);
}
////////////////////////////////////////////////////////////////////// Tag: searching for a file Tag: 269132
ref / value structs
I`m having some trouble calling functions from a c++\cli dll from my C# code.
I pass in structs (that are defined in the DLL) as ref types.
When I try this I get an error.
When I create them as value types the function works fine with the same
syntax on the C# side.
Can you also point me to some artical on the subject, since I can`t find
anything... Tag: searching for a file Tag: 269131
why the service manager doesn't start my service
Hi, all,
I have a question, and I hope to get some hints here..
I created a really simple service just to check why the service manager
doesn't start my service the second time if the first time failed..
I created an atl service through the wizard, and the only thing I do is
override the PreMessageLoop()...
HRESULT CAutoStartServiceModule::PreMessageLoop(int nShowCmd)
{
HRESULT hr = CAtlServiceModuleT<CAutoStartServiceModule,
IDS_SERVICENAME>::PreMessageLoop(nShowCmd);
if(FAILED(hr)) return hr;
//return a false here..
//log event here..
LogEvent(_T("Failed to start the service, should retry ...."));
return E_ABORT;
}
And in the service control panel, i set "Recovery options" as
First Failure: Restart the service..
Second Failure: Restart the service..
Subsequent Failure: Restart the service..
But the service was not restarted ...
I wonder maybe I miss something to report the right information back to
the service control manager..
Thanks for any help..
J.W. Tag: searching for a file Tag: 269119
Converting CString to char array
I've a CString that need to be converted to char array. Is my syntax correct?
CString c_string = "XYZ";
char char_array[20];
strcpy(char_array, c_string); Tag: searching for a file Tag: 269102
Alocating memory for vector of structs
Our need is to dynamically allocate memory for an stl vector of structs which
contain vectors in some of their fields:
vector< struct{ int; float; vector<int>; vector<int> } >
The size of the int vectors is not constant; it varies from element to
element depending on the input.
How can I most efficiently allocate the memory needed for this?
Thanks! Tag: searching for a file Tag: 269101
what's the meaning of "!!" in c++
Hi all,
Recently I encountered some code like this:
// ------------------------------------------
if( !!tmp0 )
{
TempControl->sSelection = ConvA2I((TCHAR*)tmp0);
}
// ------------------------------------------
Anyone can give a clue what it means or why the author write this
code "!!tem0" ?
why not just if(tmp0) ?
there should be some reason behind it.
Best Regards,
Lin Tag: searching for a file Tag: 269096
"Unspecified Error" while cleaning a project
Hi all. When I do a right-click on a particular project in a solution
and try to "clean" it, or look at the "properties", I get an
"Unspecified Error". I understand this must have got something to do
with my messing around with the .vcproj's and the .sln's by hand. But I
have no clue as to how to go 'bout it. I'm using VC++ .NET 2003.
Any help will be greatly appreciated. Thanks in advance.
Nishant. Tag: searching for a file Tag: 269086
console winevents and codepage change on 2 or multi cpu systems
Hey guys, any help would be appreciated.
Background:
My system basic specs is Windows XP, SP2, VC6. Intel P4 Hyperthreading.
This problem occurs only if there is more than 1 cpu(hyperthreading or
Dual Xeon).
I am using SetWinEventHook to get notification of console winevents.
Events 4001h-4007h
After I setup the hook, I run several console applications, let's use
cmd.exe as an example. all is well, notifications are coming from all
the
windows and I was happy for a while.
Yet...
When I run CMD.EXE, and then run "chcp", I get the active codepage. if
I try to change it using "chcp 437", the CMD.EXE process hangs.
Same happened if I use a console application of my own and use the api
SetConsoleOutputCP to change the codepage.
If the console process didn't hang for the first time, opening a second
console application(or cmd.exe) and changing the codepage causes it to
hang.
Assume the only line of code in the WINEVENTPROC that fires is int i=0;
No global variables, no calls. so the problem is not within the proc.
I tried WINEVENT_OUTOFCONTEXT and WINEVENT_INCONTEXT methods with EXE's
or DLL's, exact same results.
I tried hooking only 4007h event, same results.
The problems occurs only in the console events(4001h-4007h), other
events work great.
If I UnHook the events, change the codepage(works) and hook back, it
works but it's just not supposed to be this way! ! ! and it is not good
for my design.
On single processor systems it works well, on multi processor systems
it only works If I set the affinity of CSRSS to only one CPU and so on
(not a good solution obviously, just for the sake of testing...) then
all is working well.
Questions
1. WTF?
2. Am I doing something that is not thread safe ?
3. Is this a bug in windows ??????? is their api not thread safe ?
4. Not related to the problem(I am not using VB for the above problem),
does any one know why UnHookWinEvent doesn't work in VB(doesn't unhook)
? while SetWinEventHook is working great.?
Thank you very much for your time,
Lao. Tag: searching for a file Tag: 269085
Generic Class
Hi Folks,
Could you please elucidate the meaning of word "Generic" in context of C++??
Is it like "Common", or "Basic", or what???
What is the best usage of that kind of classes?
Thanks a bunch! Tag: searching for a file Tag: 269078
User Breakpoint Unhandled Exception Error VS.NET 2003
I was browsing the other posts on this topic but I need to enquire
further on it. I'm experiencing the same User Breakpoint Unhandled
Exception on one of my machines. My main desktop. Possible heap
corruption ( if it is in fact a heap corruption, how do you trace the
and remove it?). Then I decided to run the project on my laptop with
the same version of VS.NET (2003) and it ran without error or
interruption of any sort in all modes(release, debug). I'm really not
sure what else to try as I need to get it back functioning normally on
my desktop which is my main development machine. Especially due to the
fact that it has a video card supportive of the advanced graphics
technologies that I plan to use in the project. Any assistance on my
situation is much appreciated. Tag: searching for a file Tag: 269076
[newbie] new and delete
Hi,
I'm really new to C, so please excuse trivial questions:
What is the correct mechanism to delete memory that was created like that:
void AnyFunction()
{
char pBuf[300];
[...] do something with pBuf
//now, delete pBuf
delete [] pBuf;
}
Somehow the delete statement does not seem to work - can anyone tell me (for
sure) how I successfully delete objects like pBuf in the example above?
Best wishes,
Peter Tag: searching for a file Tag: 269072
Regular expression for Japanese charector set
Hi, I need a regular expression for the validating the edit control
data :
Characters that can be used:Full width characters , Half width alpha
numeric characters,half width symbols like ! # $ % & ' * + - / = ? ^ _
` { | }
Can any one solve this problem, writing a regular expression for the
above specified condition
I need it ASAP Tag: searching for a file Tag: 269069
TreeView and GetCheck() results
In a TreeView with checkbox style when I check or uncheck a box the
immediate result is always a bad result. Example: I click on a checkbox
and in the OnClick() function I go to see if the value is 0 or 1; the
value is always wrong and if I clic in the same checkbox on in another
one the result is always the previous result. I've tried with
UpdateData(true\false) but no changes happen. I can see that SetCheck() work
fine but not GetCheck . What's the problem? Tag: searching for a file Tag: 269066
Unauthorized memory allocation - Possible VC2005 bug?
Hi,
I have a relatively small Visual C++ project using MFC which allocates
unusually hight amount of virtual memory as soon as the program
starts(roughly 280MB), even before hitting the internal MFC stuff. When I
debug them program in Visual Studio 2005 with a breakpoint at the beginning
of int _tmainCRTStartup(void) function in crt0.c Windows Task Manager shows
the following information:
Memory Usage: 5,620K
Peak Memory Usuage: 5,620K
Page Faults: 1,420
VM Size: 282,360 K
Paged Pool: 632K
NP Pool: 2K
Handles: 102
Threads: 1
GDI Object: 6
Running the program in release mode produces the same result. Also,
compiler/linker settings are almost set to default.
My question why the program allocates so much VM, before even its started
WinMain() function? Is it a Windows issue or Visual C++?
Any help appreciated!
- Damon Tag: searching for a file Tag: 269052
VSflexgrid Highlight problem in VC++
I am using VSflexgrid8 ocx control in VC++ code. I need to highlight a
particular row dynamically by code not by clicking the row manually.How
to achieve that.
Second thing is if I resize the column width by mouse the highlighted
row should be present but in my programme it is disappearing.how to
hold the highlighted row even after resizing the column.
Any solution is great help to me Thanks Tag: searching for a file Tag: 269051
Quick question!
Hello,
How are you all doing today... I hope only good! :-)
I am trying to read a byte from my PC into a micro processor using RS232...
I know I know, you all though I had finally got this done... But you see, I
never really tested the part where the processor had to read the bytes in
from the PC! It appears just as complicated as the vice versa operation which
is reading in bytes from the processor by which I have done! And since the
available controls on the CPU side are very limited, I must be carefull on
what I issue from the PC side!
I am using the popular serial class... here is the problem I hope to resolve!
I am sure its got something to do with the windows variable types!!! ?
Simply put, here is the bulk of the code:
//////////////////////////////////////////////////////
LRESULT CALLBACK WndProc_CW1 (HWND hwnd, UINT message,
WPARAM wParam, LPARAM lParam)
{
TCHAR zzz[] = TEXT("5");
char xxx[1];
...other code...
case WM_COMMAND:
//Convert Wide characters to byte sized charaters
WideCharToMultiByte(CP_ACP,0,zzz,1,xxx,0,NULL,NULL);
MySerial.Write(xxx);
return 0;
...other code...
}
////////////////////////////////////////////////////////////////////////
Basically, when I converted the wide character to multi byte, and I put my
cursor over xxx, I get:
"Ã?Ã?Ã?Ã?Ã?Ã?Ã?Ã?Ã?Ã?5"
Shouldn't I just be getting the, "5".
The reason I am asking this is that my processor gets two rs232 interupts
instead of just one, and reads in "�" on the first interupt and "ÿ" on the
second interupt.
I obviously need only the "5"!
Overall I thing that I am somehow sending out wrong information, but why?
Does someone know why this is happening!
I thankyou all for any resolutions to this problem!
Sincere Thanks!
--
Best regards
Robert Tag: searching for a file Tag: 269049
Hi, I need to search for some files such as x.exe in mycomputer from
inside my code. I need to do this to set the pathes of these files for
future usage. what should I do?
golnar wrote:
> Hi, I need to search for some files such as x.exe in mycomputer from
> inside my code. I need to do this to set the pathes of these files for
> future usage. what should I do?