|
Asesh wrote: his is what I did to download a gif image from codeproject
Is URLDownloadToFile() is of any use???
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
cheers,
Alok Gupta
VC Forum Q&A :- I/ IV
Support CRY- Child Relief and You
|
|
|
|
|
My application needs to store a float number into to a byte array at the specific location. i.e. at byteArray[0] to byteArray[3] will store that float number. wrote :
byteArray[0] = ((byte*)&floatNumber)[0];
byteArray[1] = ((byte*)&floatNumber)[1];
byteArray[2] = ((byte*)&floatNumber)[2];
byteArray[3] = ((byte*)&floatNumber)[3];
but after write into a file and read back then
cout << (float) byteArray[0] << endl;
doesn't get the correct answer.
How to modify above code???
|
|
|
|
|
union FloatToCharArray {
float f;
char c[4];
};
then, you use it like this :
FloatToCharArray ftc.f = 4.12;
cout << "chars are : " << ftc.c[0] << " " << ftc.c[1] << " " << ftc.c[2] << " " << ftc.c[3];
TOXCCT >>> GEII power
[VisualCalc 3.0 updated ][Flags Beginner's Guide new! ]
|
|
|
|
|
I stored ftc.c[0] to byteArray[0];
ftc.c[1] to byteArray[1];
ftc.c[2] to byteArray[2];
ftc.c[3] to byteArray[3];
then output:
cout << (float)byteArray[0] << endl;
doesn't give the correct number.
|
|
|
|
|
of course, it can't work, you are converting only the first char into float, not the 4 chars...
use ftc.f (in my union) to retrieve the float...
TOXCCT >>> GEII power
[VisualCalc 3.0 updated ][Flags Beginner's Guide new! ]
|
|
|
|
|
This will work a bit better:
cout << *((float*)*byteArray[0]) << endl;
However, using the union described above, you could write much more clear code:
union FloatWrapper
{
float myFloat;
unsigned char myBytes[4];
};
FloatWrapper someValue;
someValue.myFloat = 1.23;
cout << someValue.myFloat << endl;
If you decide to become a software engineer, you are signing up to have a 1/2" piece of silicon tell you exactly how stupid you really are for 8 hours a day, 5 days a week
Zac
|
|
|
|
|
Oh you should show the result to us.
union good
www.codeproject.com is a good web for our programer.
I like life and I think it is living.
|
|
|
|
|
I worked on it for 3 months.But i can't write a SMTP server.Any help? Thanks a lot.
Things like that don't last long.
|
|
|
|
|
Well, one could question why you would want to do that. I think you can get tons of SMTP servers (with code), can't you?
Anyway, even so, I think you could start off by telling us what knowledge you already have to contribute to this project. You would need skills on these areas:
1) TCP/IP, as a server, to receive SMTP connections. Possibly, also multithreading, if you want your server to be able to handle several requests simultaneously.
2) Command parsing. For this you would need to investigate the SMTP protocol details. Checkout http://www.ietf.org/rfc/rfc0821.txt[^]. I bet you will find it to be a gigantic task to implement a fully compatible SMTP server. But you could settle for starting small, maybe allowing for plain text (no attach) SMTP, and progress from then on. A good design would be the key for your project to be able to evolve in small steps.
3) Relay protocol (I think it is diferent) to be able to deliver e-mails to the destination.
4) Some form of UI, to configure accounts and things like that.
5) Some form of testing. This could be the simpler task, because you probably have an e-mail client. However, it could be easier to develop your own light-weight client to make sure your test conditions are under control. A network sniffer (like Ethereal) could be used to troubleshoot the software.
Do you feel confident on these topics? If not then I would sugest you start with a simpler project. POP3 is usually simpler than SMTP, and doesn't require relay. And you would act as a client instead of a server. Of course, POP3 is not what you asked for...
I hope this helps,
Rilhas
|
|
|
|
|
I have a SDI application with 2-views. I can flick between the
2-views and there are many edit and check boxes on each view.
Its neat.
If I go to File/New, how can I make the data clear out of there?
Or, is there a way from CMainFrame to get a handle on CForm1 and
CForm2 which are both CFormViews and call the New() which clears
out all that data respectively? I cant figure out any resolution.
I tried lots of different things and nothing is working.
Please, any response any one can give me will be greatly appreciated.
Sincerely,
Danielle Brina
|
|
|
|
|
1) Get the message in the Document. Override CDocument functions:
virtual BOOL OnNewDocument( );
or
virtual void DeleteContents( );
(depending on which fits better into your situation)
2) tell your views about it.
POSITION pos = GetFirstViewPosition();
while (pos != NULL)
{
CView* pView = GetNextView(pos);
// you may have to cast to your view type here
pView->SomeFunctionYouAdd();
}
OR call:
UpdateAllViews(NULL, foo, bar);
where foo and bar are your application-specific hints (e.g. define bar==1 to mean "clear everything out"). Then watch for this in your view's OnUpdate function.
Best of Luck...
|
|
|
|
|
Hallo!
I created an ActiveX, which create an instance of another activeX at runtime and then determine the dispid with the name of a method (with the function: GetIDsOfNames(…)).
In the next step I can call this method with InvokeHelper(…).
So far, so good.
But if I want determine an EventId of a special Event with the name “CollectEvent”, I comes in trouble, because I have no plan.
Please help me to determine the eventid or give me a tip.
Thanks in advance.
Here the code for the invocation of a method:
<br />
....<br />
CWnd m_ControlWrapper;<br />
RECT rct = {0,0,5,50};<br />
<br />
BOOL bStat=FALSE;<br />
bStat= m_ControlWrapper.CreateControl(clsid, "Spectrometer", WS_CHILD, rct, this, 1212, NULL, FALSE, NULL);<br />
<br />
if (bStat == FALSE)<br />
{<br />
MessageBox ("Could not place control");<br />
return;<br />
}<br />
<br />
LPUNKNOWN pUnk = m_ControlWrapper.GetControlUnknown();<br />
<br />
LPDISPATCH pInterface = NULL;<br />
<br />
pUnk->QueryInterface(IID_IDispatch, (LPVOID*)&pInterface);<br />
<br />
<br />
CString CstrMethod = "STATUS"; <br />
BSTR BstrMethod = CstrMethod.AllocSysString();<br />
<br />
DISPID dispid; <br />
<br />
HRESULT hRet = pInterface->GetIDsOfNames(IID_NULL, &BstrMethod, 1, LOCALE_SYSTEM_DEFAULT, &dispid); <br />
<br />
m_ControlWrapper.InvokeHelper(dispid, DISPATCH_METHOD, VT_EMPTY, NULL, NULL);
<br />
....<br />
<br />
<br />
-- modified at 10:19 Thursday 20th July, 2006
|
|
|
|
|
I am attempting to access a value that the user chooses in a Combo Box.
I use :
DWORD_PTR data = m_Combo.GetItemData(m_Combo.GetCurSel());
This returns 0 to me all the time. When i check the m_Combo.GetCurSel() value, it returns the correct index. but the m_Combo.GetItemData just returns 0 for the value at that index all the time.
Am i using this correctly first off and can anyone explain why this may be happening?
|
|
|
|
|
You don't use GetItemData to retrieve the text. Take a look at GetLBText[^] instead (GetItemData is for retrieving some data that you associated with the string).
Cédric Moonen
Software developer
Charting control
|
|
|
|
|
Can you expand or give an example when you say that GetItemData is used to retrieve some data associated with the string?
Thanks,
|
|
|
|
|
|
I think you are mixing the string in the combo box (which can represent a value) and the data associated with this string. These are two different things.
Cédric Moonen
Software developer
Charting control
|
|
|
|
|
LCI wrote: This returns 0 to me all the time.
Which is probably correct, if you did not use SetItemData() to store the value.
"Money talks. When my money starts to talk, I get a bill to shut it up." - Frank
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
Hi..
Is it possible to detect that Windows has restated or has just been powered on?
Kind regards
/Kim
|
|
|
|
|
Not unless you already have an application up and running to detect such an event.
Check out the HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run registry key.
"Money talks. When my money starts to talk, I get a bill to shut it up." - Frank
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
What you mean by has just been powered
Just is an inaccurat term. If you mean that you have an application violently terminating due to system shutdown and restart then your application should leave enough traces to recover itself.
I suppose that Win32 will have an interface to give you the latest loggin time of the current user if that's help.
|
|
|
|
|
The problem is. I have made a Win32 service application witch is set to automatic start up.
For some reaches, the application unexpectedly terminates. But when I start the application with Service Manager is starts with out errors.
But I have thought about this function, witch can tell me how long the system has been up an running.
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/sysinfo/base/gettickcount.asp
Then I will try to make a delay for about 10 seconds. when system up time is less then 10 minutes.
/Kim
|
|
|
|
|
I have the folowing code for a function that reads a string from the COM5 port and then adds it to a table in the database. The value that i should read from COM is smth like "FFFFAAAAAAAAAA000C" but i only get "F". What's wrong?
void CMina_sView::OnListenCom5()
{
CSerial serial;
LONG lLastError = ERROR_SUCCESS;
DWORD dwBytesRead ;
char szBuffer[17];
char * point;
// Attempt to open the serial port (COM5)
lLastError = serial.Open(_T("COM5"),0,0,false);
// Setup the serial port (9600,8N1, which is the default setting)
lLastError = serial.Setup(CSerial::EBaud9600,CSerial::EData8,CSerial::EParNone,CSerial::EStop1);
// Register only for the receive event
lLastError = serial.SetMask(CSerial::EEventBreak |
CSerial::EEventCTS |
CSerial::EEventDSR |
CSerial::EEventError |
CSerial::EEventRing |
CSerial::EEventRLSD |
CSerial::EEventRecv);
lLastError = serial.SetupReadTimeouts(CSerial::EReadTimeoutNonblocking);
// Wait for an event
lLastError = serial.WaitEvent();
// Save event
const CSerial::EEvent eEvent = serial.GetEventType();
// Handle ring event
// Handle data receive event
if (eEvent & CSerial::EEventRecv)
{
do
{
// Read data from the COM-port
lLastError = serial.Read(szBuffer,sizeof(szBuffer)-1,&dwBytesRead);
// Finalize the data, so it is a valid string
szBuffer[dwBytesRead] = '\0';
}
while (dwBytesRead == sizeof(szBuffer)-1);
wchar_t* lpszBuffer = (wchar_t*)calloc(dwBytesRead+1, sizeof(WCHAR));
::MultiByteToWideChar(CP_ACP, 0, szBuffer, -1, lpszBuffer, dwBytesRead+1);
m_pSet->AddNew();
m_pSet->m_Nume="asas";
m_pSet->m_Serie=lpszBuffer;
CTime time = CTime::GetCurrentTime();
m_pSet->m_Data=time;
UpdateData(TRUE);
if (m_pSet->CanUpdate())
m_pSet->Update();
m_pSet->Requery();
UpdateData(FALSE);
m_pSet->Close();
m_pSet->Open();
Invalidate();
UpdateWindow();
}
serial.Close();
}
|
|
|
|
|
First, if you expect people to read that much code, for the love of god format it. Use the pre tag below this box.
Second, you already asked this question. David Crow gave you a good answer. Go read it.
Third, you should be trying to figure out if the bug is in your reading code or your string conversion code. Hence David's question.
earl
|
|
|
|
|
Hello all, by refering to article http://www.codeproject.com/internet/rpcintro1.asp, i was wondering if i allocate an memory at server side, the return the pointer.
// Server function.
const char* Server::Output()
{
m_pVar = new char[1024];
return m_pVar
}
m_pVar is Server class member. Server will delete m_pVar in its destructor. However, may I know once the Client receive the pointer,
// Client code
const char* m_pClientPointer = Output();
does client need to perform deletion on m_pClientPointer?
Thank you!
|
|
|
|