|
I have a char array defined as
char cBuffer[200]
and I want to convert this to a double.
Can anyone help with the syntax to do this?
Thanks,
Kyle
|
|
|
|
|
use:
double dblVal;
sscanf(cBuffer, "%lf", &dblVal);
|
|
|
|
|
If you mean you have a double in the first 8 bytes of the array then you can get at it like this:
double dbl = *((double*)cBuffer);
or alternatively if the bytes that contain the double start say 6 bytes into the array then the syntax is nearly the same but you need the address of the first byte of the double:
double dbl = *((double*)&cBuffer[5]);
Just one thing to be careful of is that x86 cpu's allow this casting from anywhere in memory but some cpu's have strict rules about things being aligned on even byte boundaries so if portability is important then you may need to copy the bytes using memcpy() or something first to ensure the proper alignment.
Matt
|
|
|
|
|
Casting it to double?
Or converting the contents to double?
Nish
Check out last week's Code Project posting stats presentation from :-
http://www.busterboy.org/codeproject/
Feel free to make your comments.
|
|
|
|
|
Converting the contents to double describes it well.
Kyle
|
|
|
|
|
kyledunn wrote:
Converting the contents to double describes it well.
Then the solution is elementary.
Use atof(...)
double num = atof(buffer);
Hope that helped,
Nish
Check out last week's Code Project posting stats presentation from :-
http://www.busterboy.org/codeproject/
Feel free to make your comments.
|
|
|
|
|
Yes, that did help. Thanks.
Kyle
|
|
|
|
|
How do you serialize an MFC POSITION data type and an HTREEITEM?
This questions from my dad. He told me to post it here so I can't get anymore detailed until he gets home.
-Raffi's dad
|
|
|
|
|
you don't. you find some other way to represent them. a POSITION is, well, probably just a number, an ordinal. an HTREEITEM is much more complex. if you want to serialize a tree, use something like XML, or come up with your own tree-like data structure.
-c
I don't care, and you can't make me.
|
|
|
|
|
Hey folks,
I've got a problem that I need help with, I've tried numerous approaches an have yet to find a "WHY" answer.
Some background..
In our product, which is just a big database, we've got our MAIN process which owns a big chunk of memory which holds all the TABLES, and various child processes which have READ ONLY access to those tables. All updates are done using a DATA-MANAGER thread in the MAIN PROCESS, where a child process will send a message to the MAIN process thread, telling him to update TABLEx, RECORDx, FIELDx with value Y, No problems...
We have 5-6 tables in the MAIN process which need to be READ_WRITE for all the child processes. This works fine in Windows 95/98/NT/2K, but in Windows XP, we're finding that child processes do not have READ_ONLY access to this memory.
Is anyone aware of any changes done to VirtualProtect in Windows XP?
Basically, when the memory is created/mapped in the MAIN process, we mark the memory area as PAGE_READWRITE... When we start a child process, we Map the same memory as PAGE_READONLY initially(OpenFileMapping, MapViewofFile) for the child process. Like I mentioned earlier, we have some tables that are LOCAL tables that do not go through the DATA-MANAGER-THREAD (which makes the update, then broadcasts it to the server app, etc, etc), that need to be READ-WRITE for the child processes.
When we populate the tables from the child process, if we encounter a table that's LOCAL, we change his permissions to PAGE_READWRITE:
if ( pcos->objc[*pclass].sync == LOCAL_TABLE )
VirtualProtect ( addressstart, size, PAGE_READWRITE, &prot );
In Win 95->2k, this works fine, VirtualProtect returns 1 (SUCCESS)... in XP, we get a 0, and a GetLastError(), as 47 (I think... INVALID_PARAMETER)...
For fun, we did a switch-eroo... We made the tables INITIALLY READ-WRITE for the child process, then made all tables that were !LOCAL_TABLES READ-ONLY... Fired up XP, BINGO, everything worked fine...
Is there a new rule in XP where you cannot UPGRADE the permissions when using a shared memory area, but only downgrade?
READONLY -> READWRITE failed, but, when we did the switcheroo
READWRITE-> READONLY, it worked...
Thoughts? Anyone have any direction here? Much Appreciated..
Mike
doner@obtain.com
|
|
|
|
|
Hi:
I registered a CListCtrl control in the Document class and catching (succesfully) LVN_BEGINDRAG notifications.
ON_NOTIFY(LVN_BEGINDRAG, IDC_VIEW_UNIVERSE_LISTBOX, OnBeginDragUniverseListBox)
All the hocus-popus is gone in this routine:
******************************
void CViewUniverse::OnBeginDragUniverseListBox(NMHDR* pNMHDR, LRESULT* pResult)
{
NM_LISTVIEW* pNMListView = (NM_LISTVIEW*)pNMHDR;
*pResult = 0;
// Create the drag & drop source and data objects
COleDropSource *pDropSource = new COleDropSource;
COleDataSource *pDataSource = new COleDataSource;
CDocUniverse* pDoc = (CDocUniverse*) GetDocument();
int nItems = pDoc->m_ViewUniverseListBox.GetItemCount();
if (nItems > 0) {
// Get the number of columns
CHeaderCtrl* pHeader = (CHeaderCtrl *)pDoc->m_ViewUniverseListBox.GetDlgItem(0);
int nColumns = pHeader?pHeader->GetItemCount() ;
CString sDataString;
TRY {
CSharedFile mFile(GMEM_ZEROINIT|GMEM_DDESHARE|GMEM_MOVEABLE);
TRY {
CArchive mArchive(&mFile, CArchive::store);
TRY {
CString sItems;
sItems.Format("%i\n", nItems);
//mFile.Write(sItems, sItems.GetLength());
mArchive.WriteString(sItems);
for (int i = 0; i < nItems; i++) {
sDataString.Empty();
for (int j = 0; j < 3; j++) {
sDataString += pDoc->m_ViewUniverseListBox.GetItemText(i, j) + "\t";
}
mArchive.WriteString(sDataString + "\n");
}
mArchive.Close();
} CATCH_ALL(eInner) {
AfxMessageBox("eInner");
return;
} END_CATCH_ALL;
} CATCH_ALL(eMiddle) {
AfxMessageBox("eMiddle");
return;
} END_CATCH_ALL;
pDataSource->CacheGlobalData(CF_TEXT, mFile.Detach());
pDataSource->DoDragDrop(DROPEFFECT_MOVE|DROPEFFECT_COPY, NULL, NULL);
} CATCH_ALL(eOuter) {
AfxMessageBox("eOuter");
return;
} END_CATCH_ALL;
}
delete pDropSource;
delete pDataSource;
}
******************************
I ran it in debugging mode and the inputs are written to the file. But for some reason, the drag to Excel (or other application) doesn't work. Any clue?
Thank you.
|
|
|
|
|
Any Information need.
Also .. : how can i implement Phone calls thru Internet - to local telephone station in the world ?
thanks !
|
|
|
|
|
A lot depends on what kind of hardware you've got. A decent pabx/switch would take a lot of the hardwork away.
I've done a bit of work recently with the Intertel Phone Switch and the Flexion X300.
http://www.iptelephony.org/
Michael
Communication is the first step towards enlightenment.
|
|
|
|
|
Well , what about Voice communications thru Internet ?
Something like PallTalk, etc - did anybody have some info (links, sities, books)?
|
|
|
|
|
I've heard about possibility to connect from local Desctop software thru Internet to telephone stations , and make local calls .
Does it possible without any additional hardware ? I suppose they are not used any centralised I-net servers ?
|
|
|
|
|
You'll need something at the end of the line to convert the VoIP data into "voice data" for the PST to recognise. Of course if you have an IP keyset phone at the remote end, it will do the conversion for you.
I've never seen a software only solution as most of my work has been for specific pabx and switches.
Michael
Communication is the first step towards enlightenment.
|
|
|
|
|
Does anybody knows any books/links/docs about programming Software for mobile phones ?
Samples, tools, equipments ?
|
|
|
|
|
symbian epoc
Normski. - Professional Windows Programmer
|
|
|
|
|
sorry .. i did not understand you .. ??
|
|
|
|
|
|
|
|
Hi Anonymous,
I am also interested in writing applications for mobiles. Maybe you can mail me and we can help each other.
vikasde@rediffmail.com
Best Regards
Sonu
|
|
|
|
|
I have tray aplication, and i want to create hot-keys combinations or it. How can i do it ?
|
|
|
|
|