|
AnilUnni wrote: m_baPersonImage[10] =07;
Out of boundary.
AnilUnni wrote: I need to convert this 10 byte array to hex of 5 bytes
You can convert your 10-bytes array into a a 5 bytes one (binary not hex,
hex is only a convenient numerical base) if and only if you're sure each byte of the original array ranges from 0 to 15 (as in your example).
If the above is your requirement then
BYTE target[5];
target[0] = m_baPersonImage[0] * 16 + m_baPersonImage[1];
target[1] = m_baPersonImage[2] * 16 + m_baPersonImage[3];
...
Hope that helps
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.
|
|
|
|
|
1) How many times are you going to ask this before you try something?
2) WHY would you store a number like this?
3) If you want us to write the code, please provide enough info. You called these "hexa format". Does this mean they can
go to FF or is 09 the largest "digit"?
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
for the first question,I am trying things.
for the second question, this is how it is stored in the database. If i had to change the implementation of how it is stored then I should be rewriting the entire stuff of storing in the hexa format which does not seem to be feasible
for the last question, the largest cannot be more than 09, meaning if i enter 9999999999 which is the largest number i can enter, then it is stored as 09090909090909090909 in the database, when i send it through the wire i should convert it into a hex of 5 bytes
With Rgds
|
|
|
|
|
TCHAR szSource[] = _T("09090909090909090909");
TCHAR szSourceFormatted[11];
for (int i = 0; i < 10; ++i)
szSourceFormatted[i] = szSource[i*2+1];
szSourceFormatted[10] = _T('\0');
__int64 llValue = _tstoi64(szSourceFormatted);
unsigned char BytesToSend[5];
BytesToSend[0] = (unsigned char)(llValue >> 32);
BytesToSend[1] = (unsigned char)(llValue >> 24);
BytesToSend[2] = (unsigned char)(llValue >> 16);
BytesToSend[3] = (unsigned char)(llValue >> 8);
BytesToSend[4] = (unsigned char)(llValue);
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
simple answer : no way.
you cannot store an integer which is 10 bytes wide into 5 bytes...
hexadecimal is just a matter of representation of a number, such as decimal, octal, and binary...
your number in memory will be stored with 1s and 0s...
|
|
|
|
|
Hi all,
i am writing code to create XML file which looks like this:
<code><rtcs name="Remote Target Control System">
<connection connect="Server" ipaddress="" port="27015">
<logging directory="C:\RTCSLogs\log1.log" level="5" comport="27016" maxsize="1">
<ir directory_path="C:\signalDB.xml">
To accomplish above i have created code like this:
HRESULT hr;
IXMLDOMDocument2Ptr pXMLDoc = NULL;
CoInitialize(NULL);
hr=pXMLDoc.CreateInstance("DOMDocument.4.0");
MSXML2::IXMLDOMNodePtr pRootNode= NULL;
_variant_t varNodeType((short)MSXML2::NODE_ELEMENT);
pRootNode= pXMLDoc->createNode(varNodeType,
_T("RTCS"), _T("Remote Target Control System"));
pXMLDoc->appendChild(pRootNode);
MSXML2::IXMLDOMNodePtr pRecNode= NULL;
pRecNode = pRootNode->appendChild(pXMLDoc->createElement(_T("Connection")));
MSXML2::IXMLDOMAttributePtr pRecIdAttr = NULL;
pRecIdAttr = pXMLDoc->createAttribute(_T("connect"));
pRecIdAttr->nodeTypedValue = _T("connect_val");
pRecNode->attributes->setNamedItem(pRecIdAttr);
MSXML2::IXMLDOMAttributePtr pRecIdAttr1 = NULL;
pRecIdAttr1 = pXMLDoc->createAttribute(_T("ipaddress"));
pRecIdAttr1->nodeTypedValue = _T("ip_address");
pRecNode->attributes->setNamedItem(pRecIdAttr1);
But the above code works good in MSXML2 but i want to work in MSXML4
and so i am modifying code so that it works fine in MSXML4: which is as follows:
XMLDOMDocumentPtr pXMLDoc = NULL;
CoInitialize(NULL);
hr=pXMLDoc.CreateInstance("msxml2.domdocument");
IXMLDOMNodePtr pRootNode= NULL;
IXMLDOMNodePtr pRecNode= NULL;
_variant_t varNodeType((short)MSXML2::NODE_ELEMENT);
hr= pXMLDoc->createNode(varNodeType,
_T("RTCS"), _T("Remote Target Control System"),&pRootNode)
but the problem is with i am not able to attach child node Connection with Root node RTCS:
I am not able to get the code right for the above version to do this.
The problem is CreateElementdoesn't work same in both the versions,also attributes is also different.
Regards
|
|
|
|
|
Maynka wrote: The problem is CreateElementdoesn't work
I used MSXML4 some time ago to do stuff like this and it always worked correctly.
<br />
hr= pXMLDoc->createNode(varNodeType,<br />
_T("RTCS"), _T("Remote Target Control System"),&pRootNode)
Did you evaluate the HRESULT? What is it?
Why aren't you using the ATL wrapper classes that #import will generate for you?
|
|
|
|
|
Hi all,
i want to create an XML file with root node RTCS having value remote.
Then i want to create child node of this named Connection:
which has elements:
1. Connect ,value:connect_val
2. Port,value:port_number.
actually i am able to create xml file but it is having root node and its value only:
like this:
<rtcs xmlns="Remote Target Control System">
but i am not able the attach child node Connection to this root.
Any help is highly appreciated.
Regards
|
|
|
|
|
Hello everyone,
The 3rd parameter of WriteFile is number of bytes to write,
http://msdn2.microsoft.com/en-us/library/aa365747.aspx
I am wondering if I want to write multi-byte character string or wide character string on Windows, how could I get the number of bytes?
thanks in advance,
George
|
|
|
|
|
George_George wrote:
I am wondering if I want to write multi-byte character string or wide character string on Windows, how could I get the number of bytes?
_tcslen(str) * sizeof(TCHAR)
"A good athlete is the result of a good and worthy opponent." - David Crow
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
DavidCrow wrote: _tcslen(str) * sizeof(TCHAR)
I wonder if the above expression correctly addresses multibyte strings (see [^]).
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.
|
|
|
|
|
CPallini wrote: I wonder if the above expression correctly addresses multibyte strings
Why wouldn't it?
"A good athlete is the result of a good and worthy opponent." - David Crow
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
DavidCrow wrote: Why wouldn't it?
No more objections. You're right (maybe I found something [^] clearifying your point... )
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.
|
|
|
|
|
|
Basically, I want to convert a DWORD to a LPCSTR for use in an edit box, but I don't really know how to go about this. If I can do this with an API function, that would be recommended.
|
|
|
|
|
char buf[20];
sprintf(buf, "%u", myDWORD);
|
|
|
|
|
boost::lexical_cast[^], which basically is a convenience wrapper around std::stringstream or itoa if you fell like using plain old C.
Failure is not an option - it's built right in.
|
|
|
|
|
Do you mean:"I want to show the string representation of a DWORD content in a edit box?"
If the answer is yes Then:
DWORD dwValue = ...;
CHAR buffer[34];
ltoa(dwValue, buffer, 10);
SendMessage(hWndEdit, WM_SETTEXT, (WPARAM)0, (LPARAM) buffer)
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.
|
|
|
|
|
This is exactly what I was looking for, thanks!
|
|
|
|
|
Hi,
i try to transfer a String from a DialogBox (a simple CString)to a SDIView.
There i want to print it out with (TextOut), but how can i manage the transfer ???
Please Help !!!
Many Thx
SE
|
|
|
|
|
Just after closing the dialog box, get the CString from the member of the Dialog where it is stored (or create a getter function) and put it on the screen.
Failure is not an option - it's built right in.
|
|
|
|
|
Sry I'm a little confused.
Did You have some lines of Code on how to do this and where in the code please ?
M*A*N*Y T*H*A*N*X
SE
|
|
|
|
|
From the following Dialog, I read m_Name and use it in my Program.
MyDlg.h
// MyDlg dialog
class MyDlg : public CDialog
{
DECLARE_DYNAMIC(MyDlg)
public:
MyDlg(CWnd* pParent = NULL); // standard constructor
virtual ~MyDlg();
// Dialog Data
enum { IDD = IDD_MY_DLG };
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
DECLARE_MESSAGE_MAP()
public:
// Control of the Name Edit-Field
CEdit c_Name;
// The name string
CString m_Name;
};
----------------------------------------------------------------------------
Mydlg.cpp
// MyDlg.cpp : implementation file
//
#include "stdafx.h"
#include "MyDlg.h"
// MyDlg dialog
IMPLEMENT_DYNAMIC(MyDlg, CDialog)
MyDlg::MyDlg( CWnd* pParent /*=NULL*/)
: CDialog( MyDlg::IDD, pParent)
, m_Name( _T(""))
{
}
MyDlg::~MyDlg()
{
}
void MyDlg::DoDataExchange( CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
DDX_Control( pDX, IDC_NAME, c_Name);
DDX_Text(pDX, IDC_NAME, m_Name);
}
BEGIN_MESSAGE_MAP(MyDlg, CDialog)
END_MESSAGE_MAP()
Failure is not an option - it's built right in.
|
|
|
|
|
Hi jhwurmbach,
thx for your help !
But How do you use the strName in your Code ?
When you press ok on your Dlg...
regards
CB
|
|
|
|
|
Hi,
i solved it in this way:
void CSDI_DLG_DatenaustauschView::OnDialog()
{
CDC *pDC = new CDC;
pDC = GetDC ();
MyDlg.DoModal ();
pDC->TextOut(100,100,MyDlg.m_strEdit);
}
regards
CB
|
|
|
|