|
You've probably tried #include <stdio>
You should use #include <stdio.h> (like CPallini suggested).
Or, if you want to be standard C++ compliant, you should use #include <cstdio> . Note that this will put every definition definiton in the std namespace.
But if you really want to use C++ (rather than C), you should use <iostream> instead of the C functions.
Still, printf("Value=%d", value) is more convenient than cout << "Value=" << value; . But it's still not type safe. Nor extensible. That's why you should use boost::format[^]
If you are only using C instead of C++: why?
Florin Crişan
|
|
|
|
|
Maybe because it is an alternative
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
|
|
|
|
|
I created atl com application project and I add atl composite control with connection points support to it. when we build the project a dialog resource appears then I placed combo box on dialog resource. Now how can I add variable to the combo box control and how to customize it.
thanks
Viswanadh
|
|
|
|
|
Hi All
I've developed an MMCSnapin in ATL.I have to implement drag-drop for nodes.
for that I havr to handle MMCN_QUERY_PASTE,MMCN_PASTE,MMCN_COPY events
can anyone tell me how to handle these events...
any suggesstions are highly awaited....
thanks in advance...
Rashmi
|
|
|
|
|
HI,
A::a (EStationID eStnID, VARIANT *pvtConTypes)
{
::CComSafeArray csaConType;
CComVariant varContTypes;
csaConType.CreateOneDim(VT_BSTR,4);
CComBSTR bstrName("Sim_Model1");
CComBSTR bstrName1("Sim_Model2");
CComBSTR bstrName2("Sim_Model3");
CComBSTR bstrName3("Sim_Model4");
csaConType.PutElement((long)0,bstrName.Copy());
csaConType.PutElement(1,bstrName1.Copy());
csaConType.PutElement(2,bstrName2.Copy());
csaConType.PutElement(3,bstrName3.Copy());
*pvtConTypes = csaConType.Detach();
can anyone please tell whether memory leak will occur in this code how to solve it
|
|
|
|
|
This doesn't compile, never mind run, so it's not going to leak memory.
Rather than CComSafeArray , I think you meant COleSafeArray (which has CreateOneDim and PutElement methods), which is an MFC class...
Also, the first parameter to COleSafeArray::PutElement is a long* , not a long , so passing 0, 1, 2 or 3 isn't going to work - you need to have a long variable that you pass the address of:
long index = 0;
csaConType.PutElement(&index, bstrName.Copy());
index = 1;
csaConType.PutElement(&index, bstrName1.Copy());
index = 2;
csaConType.PutElement(&index, bstrName2.Copy());
index = 3;
csaConType.PutElement(&index, bstrName3.Copy()); Aside from all that, I don't think it has a memory leak if implemented correctly.
|
|
|
|
|
HI all,
I am using Atl server for my application .
I have to transfer a file from my web application to the client . I am using the following code. But the application is unable to transfer the file
HANDLE file=CreateFile("C:\\xyz\\outsachin.txt",FILE_ALL_ACCESS,
FILE_SHARE_READ,
NULL,
CREATE_ALWAYS,
FILE_FLAG_OVERLAPPED|FILE_FLAG_SEQUENTIAL_SCAN,
NULL);
if(m_spServerContext->TransmitFile(file,NULL,NULL,"File transfer",0,0,NULL
,0,NULL,0,HSE_IO_ASYNC|HSE_IO_DISCONNECT_AFTER_SEND))
{
m_HttpResponse<<"<br>File transferred succesfully m_spServerContext";
}
else
{
m_HttpResponse<<"<br>File transferred falied m_spServerContext";
}
if(m_HttpResponse.TransmitFile(file))
{
m_HttpResponse<<"<br>File transferred succesfully m_HttpResponse";
}
else
{
m_HttpResponse<<"<br>File transferred falied m_HttpResponse";
}
Please help me out..Thanks in advance
-- modified at 4:26 Tuesday 20th November, 2007
|
|
|
|
|
Hi,
I have one MFC Application and i want to provide 30 day trial version facility to my application. Can u suggest the best way of implementing this??
Thanks & Regards
swamy
|
|
|
|
|
swamy Narasimha wrote: I have one MFC Application and i want to provide 30 day trial version facility to my application. Can u suggest the best way of implementing this??
you have to maintain some secure place so that you place your restriction of trial version. you could use registry for same
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow Never mind - my own stupidity is the source of every "problem" - Mixture
cheers,
Alok Gupta
VC Forum Q&A :- I/ IV
Support CRY- Child Relief and You
|
|
|
|
|
I am kinda very new to ATL and MFC programming i am kinda trying to control my stage motor connected to serial/com port using a sample software available online by activexperts.com it worked fine for abt month but now i guess the software a way to check evalution period which has expired so my software doesnt wrk anymore can anyone please help as to how i can work around this as i am a biomed engineer and really dont understand coding very well i have attached my code for refrence. It asl me to include 3 files i downloaded from their website.
void openport()
{
BSTR bstrTemp = NULL;
m_strDevice = "COM1";
CString strmotor;
ComPort->put_BaudRate( 9600 );
ComPort->put_StopBits ( asSTOPBITS_2 );
ComPort->put_DataBits (asDATABITS_8 );
ComPort->put_Parity ( asPARITY_NONE );
SysFreeString ( bstrTemp );
bstrTemp = m_strDevice.AllocSysString ();
ComPort->put_Device ( bstrTemp );
SysFreeString ( bstrTemp );
ComPort->put_ComTimeout( 200 );
ComPort->Open();
strmotor="SPEED X=3500 Y=3500 Z=20000";
writeport(strmotor);
DumpStageMotor(2);
strmotor= "ACCEL X=40 Y=40 Z=20";
writeport(strmotor);
DumpStageMotor(2);
strmotor= "WRITE X99=5000 Y99=5000";
writeport(strmotor);
DumpStageMotor(2);
strmotor= "JOYSTICK X-Y-Z-";
writeport(strmotor);
DumpStageMotor(2);
strmotor= "move x= 6500";
writeport(strmotor);
DumpStageMotor(2);
}
void closeport()
{
CString strmotor;
if( ComPort == NULL )
{
m_strResult = "Failed to load AComport.dll";
return;
}
m_strResult = "Please wait...";
ComPort->Close();
strmotor= "JOYSTICK X+Y+Z+";
writeport(strmotor);
DumpStageMotor(2);
}
void writeport(CString m_strCommand)
{
WCHAR wszTemp[ 1023 + 1 ];
BSTR pCommand;
CString cstrCommand;
INT i = 0;
if ( m_bComdata )
{
CString strTemp = m_strCommand;
strTemp.MakeUpper ();
strTemp = strTemp.SpanIncluding ( "ABCDEF 0123456789" );
while ( strTemp.GetLength () >= 2)
{
wszTemp [ i++ ] = strtol ( strTemp.GetBuffer ( 0 ), NULL, 16);
strTemp.TrimLeft ( "ABCDEF0123456789" );
strTemp.TrimLeft ( " " );
}
strTemp = "";
pCommand = SysAllocStringLen ( (OLECHAR FAR *) wszTemp, i );
ComPort->WriteBytes( pCommand );
}
else
{
pCommand = m_strCommand.AllocSysString ();
ComPort->WriteString( pCommand );
}
SysFreeString( pCommand );
}
CString readport()
{
BSTR pString;
CHAR szBuffer[ 16384 + 1 ] = {0};
BOOL bOpened;
if( ComPort == NULL )
{
m_strResult = "Failed to load AComport.dll";
return (m_strResult);
}
ComPort->get_IsOpened( &bOpened );
if( ! bOpened )
{
return (m_strResult);
}
if ( m_bComdata )
{
ComPort->ReadBytes ( &pString );
INT nLength = ::SysStringLen ( pString );
for ( INT n = 0; n < nLength ; n++ )
{
CString strTemp = "";
strTemp.Format ( "%02X ", pString [ n ] & 0xff );
m_strInput += strTemp;
}
}
else
{
ComPort->ReadString( &pString );
if( pString [ 0 ] != '\0' )
{
m_strInput += pString;
m_strInput += "\r\n";
}
}
SysFreeString ( pString );
return (m_strInput);
}
Dipen
|
|
|
|
|
sunny.rana wrote: I am kinda very new to ATL and MFC programming i am kinda trying to control my stage motor connected to serial/com port using a sample software available online by activexperts.com it worked fine for abt month but now i guess the software a way to check evalution period which has expired so my software doesnt wrk anymore can anyone please help as to how i can work around this as i am a biomed engineer and really dont understand coding very well i have attached my code for refrence. It asl me to include 3 files i downloaded from their website.
I would ditch the evaluation only software and just use MSCOMCtrl. Also, I think someone here wrote a COM port automation object in either the ATL or COM section of CodeProject. You could look that up too. Failing that, you could take the extreme measure of paying ActiveXperts the money they want, but the free software out there would make me reluctant to do so.
Nathan
|
|
|
|
|
Hi all!
I'm developing an standard-compliant STL associative container, and the biggest problem, by far, has been how to use the allocator template argument.
NB: I have chosen not to support alternative pointers.
I have two questions that I hope you can help me answer.
Question 1:
-----------
After having allocated a new node-object, why does one use value_allocator.construct() to construct the value instead of just passing it by assignment? I have checked out the SGI and GNU implementation of stl_tree.h, and they just use assignment for bool, size_type and pointer values, why not do the same or use placement new for other values? After all, one of the requirements for container elements is that they must be copyable and assignable.
... a possible answer could be "because construct may have wanted side-effects such as logging". If so, why only support the side-effects when constructing value_type and node_type?
Question 2:
-----------
Besides node-elements, I also employ the following struct:
struct{ link_type n; stack<my_enum> s;}
- After I have allocated new space for my struct, can I just do a struct_allocator.construct() on it, or am I supposed to only do a stack_allocator.construct() on the stack element contained?
Jens Rasmussen
-- modified at 10:42 Sunday 11th November, 2007
|
|
|
|
|
One question to start with - do you have a copy of the C++ Standard? That would probably explain the rationale for allocators better than anything else. It's $30 from ANSI[^] and can be very useful to have a copy of.
jens rasmussen wrote:
After having allocated a new node-object, why does one use value_allocator.construct() to construct the value instead of just passing it by assignment? I have checked out the SGI and GNU implementation of stl_tree.h, and they just use assignment for bool, size_type and pointer values,
bools, size_type and pointers can have no special semantics on assignment, as they're simple data. However, other objects can, as assignment should involve destruction as well as construction.
jens rasmussen wrote:
- After I have allocated new space for my struct, can I just do a struct_allocator.construct() on it, or am I supposed to only do a stack_allocator.construct() on the stack element contained?
the struct_allocator.construct() should call to stack_allocator.construct(), so should be OK, I guess.
|
|
|
|
|
Hi Stuart - and thanks for your reply!
Yeah - I probably have all the relevant books. The only part I think is missing from every explanation of Allocators, is how to use them as a library developer.
Personally, I think that the best explanation is given by Matthew H. Austern in:
http://www.ddj.com/cpp/184403759
Your answer regarding why one does not use assignment/placement new, was very adequate (and a little humiliating I might add ) - just what I needed to put it all into place!
Regarding your answer to my struct problem - I personally think that I must do a stack_allocator.construct() on the stack element and either just leave the simple data be, or if a value is provided, use assignment (It is exactly the same problem as when allocating nodes, only value_type is replaced by stack). I can't see how struct_allocator.construct() should be able to call stack_allocator.construct() - any comments?
Best regards!
Jens
|
|
|
|
|
jens rasmussen wrote: why one does not use assignment/placement new
It's probably OK to use placement new in the standard case - VC++'s default allocator::construct is implemented using placement new. However, the whole point of the allocator is to allow users to change the standard memory allocation strategy, so you should really use it whenever you a) allocate, b) construct, c) destruct or d) deallocate memory. So, when you'd naturally write 'Something* p = new Something();', you need to use allocator::allocate and allocator::construct instead.
jens rasmussen wrote: I can't see how struct_allocator.construct() should be able to call stack_allocator.construct() - any comments?
Ummmm - sorry, I didn't say what I meant to say, which was - if struct_allocator.construct() is implemented using the struct's default constructor (through placement new) then it will call stack's default constructor.
|
|
|
|
|
Wow, I real discussion about software development. It's been so long since I've seen one I just kept reading it over and over. Mesmerized by the illusion that my life as a developer has meaning beyond showing up and collecting my paycheck. I'm ok now though.
|
|
|
|
|
led mike wrote: real discussion about software development
I generally have several of those a day at work - I work for company developing safety-critical software, so the management does actually care that we do the job right
|
|
|
|
|
Stuart Dootson wrote: I work for company developing safety-critical software, so the management does actually care
I work for and with a bunch of monkeys
|
|
|
|
|
What kind of monkey business is that? Is that why you seem to go bananas after reading some of the posts on Code Project?
"We make a living by what we get, we make a life by what we give." --Winston Churchill
|
|
|
|
|
George L. Jackson wrote: Is that why you seem to go bananas after reading some of the posts on Code Project?
Hey! I resemble that remark.
|
|
|
|
|
Hi All,
I'm having trouble getting a file into a list. What I don't want to do is read a line (string), and then push_back() for each character.
Is anyone aware of the ctor I'm interested in which takes an ifstream ?
I can't believe how rusty I am with STL...
Thanks,
Jeff
std::list< char > certificate;
std::ifstream file;
<br>
file.open( "..//smime.p7b", std::ios::binary );
<br><br>
if( false == file.is_open() ) { return 1; }
<br><br>
char c;
while( file.get( c ) )
{
certificate.push_back( c );
}
<br><br>
std::cout << "Certificate Size: ";
std::cout << certificate.size() << std::endl;
<br><br>
file.close();
|
|
|
|
|
Why do you need this file loaded in a list<char> object instead of a vector<char> ? I mean, wouldn't something like this suffice (error checks omitted)?
vector<char> buffer;
ifstream file;
size_t fileSize;
file.open( "..\\smime.p7b", ios::binary );
file.seekg( 0, ios_base::end );
fileSize = file.tellg();
buffer.resize( fileSize );
file.seekg( 0, ios_base::beg );
file.read( &buffer.front(), buffer.size() );
|
|
|
|
|
Hi gleat,
gleat wrote: Why do you need this file loaded in a list<char> object instead of a vector<char>?
I'm using it to help me parse the input. With a list (or stack) once a top/pop occurs, I don't have to worry about adjusting a pointer (or index) into the array. Also, I can push back values without concern for book keeping.
Jeff
|
|
|
|
|
Using std::list like this is very inefficient; it's essentially a doubly liked list with -- in your case each -- each node containing a single char . You'd be better off using a std::vector .
Steve
|
|
|
|
|
Hi Steve,
Thanks for the reply.
Stephen Hewitt wrote: Using std::list like this is very inefficient;
I should have stated the files are small - less than 5KB. I desired to simplify insertion and extraction. With the list, both operations are O(1) (constant time), with a memory footprint ~= 3 times original files size. I do not need random access (vector). Also, I do not need to search.
Stephen Hewitt wrote: You'd be better off using a std::vector.
With vector, I loose O(1) extraction (extraction is linear from front or middle). Insertion is O(1) if at the end. But I have to manage an index or pointer. However, size ~= 1x.
Taking from SGI's site on vectors:
Vector is the simplest of the STL container classes, and in many cases the most efficient. As the docs state, "in most cases". In my case, I am working on a parser/scanner (no need for the tokenizer). I believe if I wanted to lessen memory needs, I could use an slist. But out of habit, I grabbed a list.
In the end, I am willing to trade memory for time (and simplicity).
Thanks for the input,
Jeff
|
|
|
|
|