Need some assistance with a function

Hi,

I'm a complete newbie, with no formal training trying to learn from a bunch 
of books.  Unfortunately, there is much not in those basic books.

First, I'm programming a WIN32 app which is an add-on.  I do need to include 
windows.h, and it would seem this prevents me from using any MFC stuff.

Is the CByteArray class an MFC thing?

Can I do something like this:

	CByteArray mac;
	mac.SetSize(MAC_DIM);

	for( int i = 0; i < MAC_DIM; i++ )
	{
		macAddress[i] = guid.Data4[i+2];
	}

meaning access the elements with array syntax?

Finally, I'm completely lost on how to write a functinon

	void MyClass::Buffer2HexString( CByteArray& , string& );

which, will return the array of bytes as a hex string, meaning convert the 
byte array to a string of hex digits that can be printed easily.

Might even be better to just return a string object, but what is really just 
driving me crazy is the proper "UNICODE" aware way to do the above for a 
small array of 6 bytes.

Patrick

0
Stick (12)
6/3/2007 10:30:00 PM
vc.mfc 33608 articles. 0 followers. Follow

4 Replies
516 Views

Similar Articles

[PageSpeed] 47

CByteArray is class library of MFC.
You can use this class like as CString ,  CStringArray.
You can set/get some data from it by [] operator.

It's easy to use. check the website,

http://www.google.co.kr/search?hl=ko&q=CByteArray&lr=


-- 
WebSite :
  Realization of Dream { imagine your dream} -  http://rodream.net

WebMail :
  rodream@naver.com


"Stick" wrote:

> Hi,
> 
> I'm a complete newbie, with no formal training trying to learn from a bunch 
> of books.  Unfortunately, there is much not in those basic books.
> 
> First, I'm programming a WIN32 app which is an add-on.  I do need to include 
> windows.h, and it would seem this prevents me from using any MFC stuff.
> 
> Is the CByteArray class an MFC thing?
> 
> Can I do something like this:
> 
> 	CByteArray mac;
> 	mac.SetSize(MAC_DIM);
> 
> 	for( int i = 0; i < MAC_DIM; i++ )
> 	{
> 		macAddress[i] = guid.Data4[i+2];
> 	}
> 
> meaning access the elements with array syntax?
> 
> Finally, I'm completely lost on how to write a functinon
> 
> 	void MyClass::Buffer2HexString( CByteArray& , string& );
> 
> which, will return the array of bytes as a hex string, meaning convert the 
> byte array to a string of hex digits that can be printed easily.
> 
> Might even be better to just return a string object, but what is really just 
> driving me crazy is the proper "UNICODE" aware way to do the above for a 
> small array of 6 bytes.
> 
> Patrick
> 
0
rodream (49)
6/4/2007 12:22:00 AM
Hi,


"Stick" wrote:

> Hi,

> First, I'm programming a WIN32 app which is an add-on.  I do need to include 
> windows.h, and it would seem this prevents me from using any MFC stuff.

This is not the case. Windows.h doesn't [and cannot] "prevent" from using 
MFC. Rather it is already included by MFC headers. So it is already there in 
an MFC project.


> Is the CByteArray class an MFC thing?

Yes.

> Can I do something like this:
> 
> 	CByteArray mac;
> 	mac.SetSize(MAC_DIM);
> 
> 	for( int i = 0; i < MAC_DIM; i++ )
> 	{
> 		macAddress[i] = guid.Data4[i+2];
> 	}
> 
> meaning access the elements with array syntax?

Yes. operator [] has two overloads; one of them returns a non-const 
reference of an element to allow it to be used as l-value.

> Finally, I'm completely lost on how to write a functinon
> 
> 	void MyClass::Buffer2HexString( CByteArray& , string& );
> 
> which, will return the array of bytes as a hex string, meaning convert the 
> byte array to a string of hex digits that can be printed easily.

Use std::stringstream or _ttot or smth else. A typical code might look like 
so;

CString ByteArrayToHexes(const CByteArray &array)
{
	CString res;
	for (int j = 0; j < array.GetSize(); j ++)
	{
		BYTE val = array[j];
		TCHAR buf[4];
		_itot(val, buf, 16);
		res += CString(buf);
	}
	return res;
}

> Might even be better to just return a string object, but what is really just 
> driving me crazy is the proper "UNICODE" aware way to do the above for a 
> small array of 6 bytes.

If _UNICODE is defined, _itot works with unicode symbols.



-- 
======
Arman

0
armancho_x1 (249)
6/4/2007 5:43:00 AM
See below...
On Sun, 3 Jun 2007 15:30:00 -0700, Stick <Stick@discussions.microsoft.com> wrote:

>Hi,
>
>I'm a complete newbie, with no formal training trying to learn from a bunch 
>of books.  Unfortunately, there is much not in those basic books.
>
>First, I'm programming a WIN32 app which is an add-on.  I do need to include 
>windows.h, and it would seem this prevents me from using any MFC stuff.
>
>Is the CByteArray class an MFC thing?
****
Yes
*****
>
>Can I do something like this:
>
>	CByteArray mac;
>	mac.SetSize(MAC_DIM);
>
>	for( int i = 0; i < MAC_DIM; i++ )
>	{
>		macAddress[i] = guid.Data4[i+2];
>	}
>
>meaning access the elements with array syntax?
****
Yes.  Although you could also have written i < mac.GetSize()
****
>Finally, I'm completely lost on how to write a functinon
>
>	void MyClass::Buffer2HexString( CByteArray& , string& );
>
>which, will return the array of bytes as a hex string, meaning convert the 
>byte array to a string of hex digits that can be printed easily.
*****
CString MyClass::Bufer2HexString(const CByteArray & bytes)
    {
     CString result;
     for(int i = 0; i < bytes.GetSize(); i++)
       {
        CString t;
        t.Format(_T("%02X"), bytes[i]);
        result += t;
       }
     return result;
    }

string is not a particularly good type to use in MFC, and there is no reason to pass it as
a reference parameter to a void function when you can create a value-returning function.
*****

>
>Might even be better to just return a string object, but what is really just 
>driving me crazy is the proper "UNICODE" aware way to do the above for a 
>small array of 6 bytes.
****
For 6 bytes, the simplest method is

CString s;
s.Format(_T("%02x%02x%02x%02x%02x%02x"), bytes[0], bytes[1], bytes[2], bytes[3], bytes[4],
bytes[5]);
return s;
*****
>
>Patrick
Joseph M. Newcomer [MVP]
email: newcomer@flounder.com
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm
0
newcomer (15975)
6/4/2007 6:04:52 AM
On Mon, 04 Jun 2007 02:04:52 -0400, Joseph M. Newcomer
<newcomer@flounder.com> wrote:


>string is not a particularly good type to use in MFC

I agree with Joe.
And if you need the Unicode-aware style of MFC CString, you might
consider defining your own Unicode-aware version of std::string, e.g.:

 typedef std::basic_string< TCHAR > tstring;

MrAsm
0
mrasm (715)
6/4/2007 8:12:33 AM
Reply:

Similar Artilces:

Vista
I upgraded to Windows Vista and I am now receiving the r6025 pure virtual function call error when using Money 2006 I tried this Support Article http://support.microsoft.com/kb/240437 but still no success. Most of those .dll files are not found on my computer. Any Ideas, In microsoft.public.money, Gabriel wrote: >I upgraded to Windows Vista and I am now receiving the r6025 pure virtual >function call error when using Money 2006 > >I tried this Support Article http://support.microsoft.com/kb/240437 but >still no success. > >Most of those .dll files are not found on...

Help needed. Word question about segmented line..
I'm typing a manuscript. Somehow I must have pressed something wrong because I've gotten a segmented line after a number of paragraghs that I can't delete. They just shift up and down. Does anyone know how this happened and how to get rid of these lines? Thanks. Look up "borders" in the Word help. What you have is a paragraph border. The Help explains how to remove it. "How it happened" is probably due to Tools>AutoCorrect>Autoformat as you type." Look that up in the help too. The AutoFormat dialog is in three sections: I recommend turning OFF...

Need some Basic Help #2
Harlan Grove Wrote: > > it may be much simpler just > to have the other users enter their data without macros. Yes, I can see what you're saying, but we've got users who insist o using the left right arrows, or tab key, etc. instead of the Enter key because the macro was set up to automatically add an interger of "1 which would be used in tabulation. Thanx for trying to help tho....muc appreciated. I gotta find some books. <br>Thank You again -- shboo ----------------------------------------------------------------------- shboom's Profile: http://www.excelfor...

much needed If/or statement help
Hello, I am not an experienced excel user however I need to find a way fo excel to do a function for me and I have had no luck with if/then/o statements. My question is this. I need a function that will if I pick a selection off a drop down lis present me with a value associated with it. For example. I hav different machine sizes 110,245,385,500,720 and 950 they are in a dro down list. I need to associate electric rates to each of them. 110 4.00 245=4.50 385=5.00 500=5.50 720=6.00 and 950 = 6.50. So when I pic the machine size off of my drop down list in say cell c3 I need th electric rat...

Copying and Filling Cell With Functions
I have an Excel page that has refrences to another worksheet ie =May!B2 I want to create a generic spreadsheet that I can just copy for each month but when I do I get ='[May Commissions Sheet.xls]May'!B2 is there a way to advoid this? And also when I try and do a fill instead of trying to copy I get =May!B3 or I tried typing in cell M2, =May!B2 and in cell M3, =May!C2 and then tried to do a fill that way for Excel to get an idea of what i was trying to do and it ends up putting =May!B4 in M4 and =May!C4 in M5 and =May!B6 in M6 etc. Can anyone help me cause I am about to lose i...

Stuck in review and need to be in design.
I am using Visio 2007. I need to complete the diagram that I have been working on and I hit the review key by mistake. How do I get back to the design screen? On Wed, 4 Nov 2009 16:14:01 -0800, cameron <cameron@discussions.microsoft.com> wrote: >I am using Visio 2007. I need to complete the diagram that I have been >working on and I hit the review key by mistake. How do I get back to the >design screen? menu Tools -> Track Markup and then close the Review window. -- Regards, Paul Herber, Sandrila Ltd. DFD/SSADM for Visio http://www.visio-dfd.sa...

Functions greyed out when using Pivot tables
I have an end user who is using pivot tables, and they were working fine up until the end of Jan. Whe she added her data for Feb and went to sort using the privot table order function they were all greyed out. She was originally using Excel 2k. Think that something had just become corrupt we upgraded her to Office 2K3. This did not solve the issue. I have insured the Office has been activated and that the sheet is not protected. We can send the sheet to another user and it functions correctly, as should. Anyone see this before or have any ideas? ...

Need to import contacts from Outlook to Outlook Express
I have a freind having trouble with email on the road and she needs to start using Outlook Express rather than Outlook. How do you import Contacts from OUtlook into Outlook Express. Thanks in advance Hi Donnie, please search the *.wab file on your computer after that FILE | IMPORT | Adressbook -- Ich habe nichts gemacht, gestern gings noch! Bitte in den Newsgroup antworten damit jeder etwas davon hat. Bravestar@Datenschutzministerium.de "Donnie" <ymivey@hotmail.com> schrieb im Newsbeitrag news:uR0#ZZBcEHA.2352@TK2MSFTNGP09.phx.gbl... > I have a freind having trouble w...

Need to block emails slipping past my IMF filters
Occasionally I get a few ejunk emails that seem to slip past my SPAM filters. Below is the email header information. I want to block these certain emails in ESM. Using the below given information what would you suggest is the best way. SBS 2003 Premium Exchange 2003 IMF ISA 2000 Microsoft Mail Internet Headers Version 2.0 Received: from 222.232.76.172 ([222.232.76.172]) by MYDOMAIN.COM with Microsoft SMTPSVC(6.0.3790.211); Thu, 26 May 2005 07:25:38 -0700 Received: from [84.185.151.122] (port=2540 helo=[Kirby]) by 222.232.76.172 with esmtp id 4361051673Edgardo80906 for use...

Really need help finding the Clean Sweep Utility for Exchange 5.5
I don't have the back office resource kit and apparently I need to run the clean sweep utility on my mailbox to clear out corrupted rules. I'm running Outlook 2003 and Exchange Server 5.5 with SP4 and hotfixes applied. I've tried everything that has been suggested to date with the excption of the clean sweep utility. Does anyone know where I can find this? Thanks, Larry ...

Using functions after importing data from Access
I was successful in importing data from a table in Access. However when I try to use a function such as "Count" it will not work. It just displays a zero even though the formula looks correct. Another question I had was when I import data from Access to Excel is there a way if I add a record in Access it would make the same change in Excel? What happens if you use COUNTA instead of COUNT? If that will give you a result that is correct then the numbers are text, try this Format the import number column as general or numbers etc (NOT text) select the column, do data>text to ...

Office Assistant Downloads
Hello, I was wondering if there is anywhere that I might be able to find a download for the Excel Office Assistant characters. I have misplaced the CD with the different choices and I have searched the net high and low, any help would be much appriciated. I am looking for the "cat" character in perticular. Thanks Kollatos, You're gonna' need the installation CD. Either that, or learn to love the "Clipee" John "Kollatos" <waterfrontgems@rogers.com> wrote in message news:035501c3906b$bb95c140$a101280a@phx.gbl... > Hello, I was wondering if...

VBA function missing its parameters
I'm creating my first VBA Excel formula in a couple years. I can pic the formula in the list of available functions, but the function' parameter is not visible. If I assign the formula to the cell anyway the cell only shows: #NAME? So, even when I pick the formula from the module, Excel complains abou the name. For example, the formula in the cell looks like: =test.xls!Module3.DoubleText() I can force a parameter into the function call, =test.xls!Module3.DoubleText("abc") but it doesn't matter since Excel doesn't see the parameter in th function definition. The e...

exchange 2000 server 2003 native forest functional level
I raised the forest functional level without thinking about what effect that might have on my exchange server 2000. When I ran The exchange best practices tool it told me I needed to update RUS. KB873059. How serious of an issue is this, are there other issues I may have, and how do I get the file referenced in this KB without paying for support? Hi, If you do have the problem described in the article you just call Microsoft PSS and ask for the hotfix - normally this won't be charged. Leif "Nathan0909" <Nathan0909@discussions.microsoft.com> wrote in message news:F...

RASENTRY and dwfOptions2 in Win XP Need Help!
Hi, I have Win XP Professional Polish wersion. I try to write some code in VC++.NET for disable programmaticaly Negotiate multilink for single-link connection but I can;t compile it because the compiler says that the version is incorrect. I put the code like: WINVER >= 0x0501 and than compiler works great but I know that XP support Negotiate multilink but after when I run my code, it's like this version of the OS don't support this option or my RAS.h don't let use this option. I really don't know where is the problem Please help me. Silvester /_cut_this_/smadej(at)slycom (...

Need to create a field validation against another CRM Enity
I have a client that needs to validate a custom field on entry to check to make sure the value does not already exist. The field is a ID code from a legacy system that uniquely ID's the contact. We need to search the current contacts for the ID field to check and make sure the entered ID code is not a duplicate. Does anyone know of any code snippets that may do this or code that show how to query the current enity for an existing ID? Any help will be much appreaciated. Al Pemberton ...

EXACT function #2
Can you use the EXACT function on a range? The help says you can, but I have been unable to get it working. A1="burt" B1="burt" =Exact(A1,B1) = true HOWEVER.... A1="burt" B1="ernie" B2="big bird" B3="burt" {=Exact(A1,B1:B3)} = false Whats up with that? -- chrisrowe_cr ------------------------------------------------------------------------ chrisrowe_cr's Profile: http://www.excelforum.com/member.php?action=getinfo&userid=25220 View this thread: http://www.excelforum.com/showthread.php?threadid=390163 Try this...

Emergency utility needed
Unknown to me, my backups for the past week were failing and I had a disaster. I have restored last weeks backup and I still have the drives that failed. I have last weeks data up and running, but I can't find anything that will replay the logs that I have since then. How can I get the log files that I have been accumulating for the past week to run and add their data to the priv1.edb? After market utilities are OK. how did you restore? if you'd restored from an online backup, the transaction logs would have all replayed... "Jordan" <nojunk_allowed@nospam.co...

Using only dates needed in Excel 2007 chart
I'm trying to Chart data from a table and when I create a chart it adds in the days between mine. I only want working days. This is in Excel 2007. Change the x-axis to catgegory, not Time Scale. (Chart options, axis) This will display only the data you've given XL. -- Best Regards, Luke M "HFST04" <HFST04@discussions.microsoft.com> wrote in message news:161B5351-A851-4776-A1F0-0E838A1722EE@microsoft.com... > I'm trying to Chart data from a table and when I create a chart it adds in > the days between mine. I only want working days. This is in...

Which function and how?
Hello, I'm using Excel 2003 Can anybody help me please, I have a worksheet that has a list of fabric names (with some names duplicated and sometimes in different areas of the list, ie; chenille, chenille, Pampas, Aster, Pampas, Chenille) and next to it is a list of quantities. What I want to do is on another work sheet work out how much chenille, Pampas and Aster without the need to write everything down more than once. so for instance a column with Chenille, Pampas and Aster, and the next column with the corresponding quantities all added up for me. -- ...

Need help cleaning up an email list in Excel
I have a very large contacts list in Excel. One column is for email addresses. Before I send off an email to these folks, I want to make sure they will all work. There are two things I need help with: 1. How do I find all cells WITHOUT an "@" sign? 2. How do I find all cells with more than 1 "@" sign? Basically, I want to know that there is only email address in each cell and that it is legitimate. Any help you can provide would be most appreciated! Thanks! I just realized re-reading my post, that it might look like I'm a spammer, but I promise I'm jus...

I need OWA to ask for username and password
Hi, When I go to http://myserver/exchange, it appears OWA and I can see my e-mail without asking me my user and password. But I would like OWA to ask my user name and password, how can I do this? -- Thank you, M.G. Have you already authed to the page once (ie the username and password are stored in your client). or have you used the username and password for access to the client? Try to logon using a local account to the computer and then logon to OWA. (Tips: Activate form-based logon) "M.G." wrote: > Hi, > > When I go to http://myserver/exchange, it appears...

Need Help in RMS 1.3 Configuring Peripherals
Hello I started a new job a few months ago and have never worked with RMS before. With that said I need help getting a new pc setup to talk to the, Barcode Scanner, Credit Card Printer, Pole, and Cash Drawer. I have the PC talking to the database so you can see inventory it is just not working with the Peripherals. I know there has to be a place in the software to configure these I just do not know where. Can someone help me out? For Store Operations most of the configurations you mention are found in the Store Operations Manager - go to Database; Registers; Register List and click on ...

How can I surface function/script parameter aliases to Get-Help?
I am starting to use the new Comment-Based Help feature for functions and scripts, but I do not see a way to surface aliases for parameter names to Get-Help. Example: Script file named Test-Me1: --begin file-- Param( [Alias('osn')] [string]$OptionSetName ) <# ..PARAMETER OptionSetName The name of an entry in the OptionSet XML file. #> --end file-- At a PowerShell prompt, I type: Get-Help -Full ./Test-Me1 Output: NAME C:\Temp\Test-Me1.ps1 SYNOPSIS SYNTAX C:\Temp\Test-Me1.ps1 [[-OptionSetName] <String>] [<CommonParameters...

Opening Powerpoint or Excel starts up "Microsoft Word X Setup Assistant"
I have Office V.x installed on my Mac OS X system (Jaguar) Whenever I start Word, things go fine. Whenever I start Powerpoint or Excel, I have to go through the "personalize" dialog (It says "Microsoft Word X Setup Assistant" in the title bar). Any ideas how to stop this? I've already removed the preferences, but it didn't help. In article <a0dbff37.0312191139.3303a86b@posting.google.com>, tpzahm@juno.com (Tom Zahm) wrote: > I have Office V.x installed on my Mac OS X system (Jaguar) > > Whenever I start Word, things go fine. > > Wheneve...