Code of the original CFrameWnd::OnDDEExecute is buggy & doesn't wo

I had encountered a problem with DDE support and processing while using MFC7.1 
Open this routine's source located in a file "winfrm.cpp", and see for your 
very self. 

CFrameWnd::OnDDEExecute, (files: afxwin.h and winfrm.cpp)

The following code is provided by Microsoft
////////////////////////////////////////////////////////////////////////////////////////////////////
// get the command string
	TCHAR szCommand[_MAX_PATH * 2];
	LPCTSTR lpsz = (LPCTSTR)GlobalLock(hData);
	int commandLength = lstrlen(lpsz);
	if (commandLength >= _countof(szCommand))
	{
		// The command would be truncated. This could be a security problem
		TRACE0("Warning: Command was ignored because it was too long.\n");
		return 0;
	}
	GlobalUnlock(hData)
////////////////////////////////////////////////////////////////////////////////////////////////////

There are two hints here:
1. Hint (most important)
The thing is that  in a furhter call to AfxGetApp()->OnDDECommand(szCommand) 
szCommand goes uninitialized!!!  That code is not safe, however DDE would not 
work anyway (the better thing would be if 0 == szCommand[0]) !!!

2. Hint (less significant)
LPCTSTR lpsz .... and this guys use lstrlen(lpsz)! What if I compile my 
program with _UNICODE, UNICODE defined?

I had made some modifications to the code above and got the things working!
Suggestions
////////////////////////////////////////////////////////////////////////////////////////////////////
	TCHAR	szCommand[_MAX_PATH * 2];
	LPCTSTR lpsz = (LPCTSTR)GlobalLock(hData);

	if ( _tcslen(lpsz) >= _countof(szCommand) )
	{
		// The command would be truncated. This could be a security problem
		//
		TRACE0("Warning: Command was ignored because it was too long.\n");
		return	0;
	}

	// copy command data to our buffer and perform unlock operation
	//
	_tcscpy(szCommand, lpsz), GlobalUnlock(hData)
////////////////////////////////////////////////////////////////////////////////////////////////////

This code I give possesses no bugs mentioned above. What do you people think 
about the matter? I'd spent some time to locate a problem of non-functional 
DDE in the project and finally got the solution. This might save your time 
around...

I hope Microsoft would fix their code.

0
lex57ukr (1)
11/24/2004 12:17:05 PM
vc.mfc 33608 articles. 0 followers. Follow

1 Replies
409 Views

Similar Articles

[PageSpeed] 29

> 2. Hint (less significant)
> LPCTSTR lpsz .... and this guys use lstrlen(lpsz)! What if I compile my 
> program with _UNICODE, UNICODE defined?
> 

lstrlen has a flavour for Unicode.  On the other hand, it is deprecated and 
should not be used.
0
2/12/2005 6:57:04 PM
Reply:

Similar Artilces:

can we copy the code from the addin to excel workbook
Is there any code thru which we can copy the code from addin to a excel workbook .. in the addin i have a code written in thisworkbook and have 1 module .. The process requires you to save the macro as a BAS file then read the BAS file into the 2nd workbook. Chip Pearson has good instructions at his website 'Programming In The VBA Editor' (http://www.cpearson.com/excel/vbe.aspx) Read the two bullets at the top of the webpage carefully especially �Next, you need to enable programmatic access to the VBA Project. In Excel 2003 and earlier, go the Tools menu (in Excel, ...

Loan Originators Needed
We are looking to expand accross the country!!! $2000-$3000 / Month Part Time Income No Experience Needed - Full Training Provided No License Required - Earn While You Learn Work Towards Ownership - Part Time / Full Time email: mybest22002@yahoo.com call: 407-970-1295 ...

HMTL Code !!!
Hi All, I have a friend who gets all the mails in the form of the Coding. For example, all the emails he gets are not in the normal format, they are in the HTML code like message. I am having a nice vacation. Take care of your health. The above text would appear as I am having a nice vacation.<BR> <BR> Take care of your health.<BR> Please help.... ...

assert in CFrameWnd::NotifyFloatingWindows
Hi, I'm trying to track down an occasional crash I'm getting while calling into "PeekMessage" right after my application has been activated (usually from Alt-Tabbing between my application and other appliations). The call into PeekMessage() eventually filters down into CFrameWnd::NotifyFloatingWindows(), and the source code included with my visual studio for this function has this little loop at the bottom: // then update the state of all floating windows owned by the parent HWND hWnd = ::GetWindow(::GetDesktopWindow(), GW_CHILD); while (hWnd != NULL) { if (AfxIsDescenda...

code needed, please
I have a list I need to do some arranging in. Column A (moving down one after another i.e A1, A2, etc) first has the company name, then under it is the street address, then under that is the city. It now repeats with new information (every 3 lines are the same and there are no spaces between the companies although in the end I would like there to be 1 space). Now comes the tricky part. In column B cell number 1 is the contact information for the company in cells A1,A2,A3 and I would like that to appear directly below the companies, and in column c we have the phone numbers which woul...

code will run using And IsNotNull
I have the following event procedure on the close event of a form the code works fine if I only use the first part If (Me.OrderStatus) = "Cancelled" Then DoCmd.OpenForm "CancellationForm" End If End Sub If I try to run as shwon below it halts Private Sub Form_Close() If (Me.OrderStatus) = "Cancelled" And IsNotNull(Me.txtDateConfirmed) Then DoCmd.OpenForm "CancellationForm" End If End Sub If I try just the the following it also halts Private Sub Form_Close() If IsNotNull(Me.txtDateConfirmed) Then DoCmd.OpenForm "CancellationForm" End If End ...

Reason codes #3
I am trying to use reason codes to track data in one RMS DB with another DB- I am looking at the Inventory transfer from main to offline and return to inventory offline.. But not sure how this would work? Anyone doing this? Thanks brent HI Brent, thsi you can do so, Go to SO Manager and then go to Database > Reason Code. and then clik the new. Like you said give any name to Code i.e. Return and in description: put any thing, Then for the Type select "Return to main inventory" or "Return to offline inventory" as soon as you will do the return automatically corss...

window updates error code 80070422
Hi, I keep receiving this error message window update encountered unknown error with error code 80070422. I am using window vista home basic sp1, 32 Bit. I have done trouble shooting via ms website, and manual update. and still getting the same error message. Please advise what is next step. Thanks and happy new year -- Kteowee See... Error message when you try to install updates by using the Windows Update Web site or the Microsoft Update Web site: "0x80070422": http://support.microsoft.com/kb/958043 kteowee wrote: > I keep receiving this error messa...

How to change password for outlook email. No one know's original
My boss wants me to create an email data base in microsoft outlook. I've imputted several dummy addresses & attemted to send to my personal email to make sure it was working. However, a box requesting a password keeps appearing & no seems to know the password. I cannot create a new one without knowing the old one. Also, I was told that a data base has to be created in microsoft acces not outlook. Is this true? Help!! Can you please define email database so that I understand what it is you're trying to create? Are you trying to create an email address/contacts list? --...

JScript Code not Working on Bulk Edit Form
Hi, I've put a good deal of code into the Account form to disable the majority of the data fields in the Account form when the Account becomes a "Customer" (CustomerTypeCode = "3" or "Customer"). In order to edit these fields, certain users are able to "unlock" the form by entering a password into a JScript input box. Once the record is saved (and the page reloads), the OnLoad event disables these fields again. This works fine in all but one situation. When a user edits multiple records using the "Bulk Edit" feature in the Account ...

Project 2007: Managed Code Add-in for Importing Tasks from Excel
All, I downloaded and tried to install the below add-in: Project 2007: Managed Code Add-in for Importing Tasks from Excel http://www.microsoft.com/downloads/details.aspx?FamilyId=416B606A-88C8-496F-9AD3-9AFA09780E12&displaylang=en Do I need Visual Studio to install this or is there a simple step by step walk thru on how to install it? Thanks. Cole Hi Cole, hope you are well. The download at the link below provides the complete source code files which need to be compiled by MS Visual Studio 2008 Beta 2 or later, with Visual Studio Tools for Office (VSTO) before use...

INTERNAL R-TREE ERROR code=32
I got an error while in Sales Transaction Entry **** INTERNAL R-TREE ERROR **** code=32 string=run_prog bip This was then followed by a message: A Severe Error Has Occured! 2:32 Anyone have any thoughts on this? Hi wes check out the custsource article: https://mbs.microsoft.com/knowledgebase/KBDisplay.aspx?WTNTZSMNWUKNTMMYMXTYYKSWTLKQNNOXWVVSZYRXYRPXYVNQTWKQWXZVLQKKMKRV I know it is not the same code error or module but if I had to guess the error is happening for the same reason. Fliehigh "Wes VanAlstyne" wrote: > I got an error while in Sales Transaction Entry >...

Code #2
The following code works well, however how can I change this to run with a command button. Also is there any way I could delete some columns from the sheets as well. Private Sub Workbook_Open() Dim wb As Workbook 'copy all sheets Worksheets.Copy Set wb = ActiveWorkbook Application.DisplayAlerts = False 'delete the sheets you want wb.Sheets(Array("Suspense", "RCA exc RIM", "Operations summary", "RCA incl RIM", "First Qtr", "Second Qtr", "Third Qtr", "Fourth Qtr")).Delete Application.DisplayAlerts = Tr...

Error Code 3020 after setting Filter
Hello, I am porting an Access 2002 database to Access 2007 which has an option group that turns on and off a filter. This works fine in Access 2002 and filters as it's supposed to do. However, in Access 2007 when I select a filter and then try to go to another record I get the error : "Update or CancelUpdate without AddNew or Edit". I know what it means that an update on a recordset was encountered without a preceding Edit or Addnew but I did not do an update. I have traced the code after the filter is set and there is no update. When I get the error I cannot break in...

Coding Inputmasks
Hi Group, I have what is probably a basic question that shows my (lack of) knowledge as to how forms and subforms interact. I have frmClients into which I enter various data. It has a primary key PacketNo. I also have a subform frmSpClients whcih contains similar data to frmClients and is linked by the primary key PacketNo. I have telephone fields in each form. In frmClients I have coded the text boxes for inputmasks dependent upon the number of digits entered. It works fine in frmClients, but it does strange things when I use the same code (with appropriate changes tot he contro...

Dexterity Coding-Calculating diff betn dates & convert to months
Hi all, I'm coding a new window for GP 7.5 in Dexterity. I'm trying to calculate the difference between 2 dates and convert into months. Has anybody the code for doing that? In Dex, subtracting 2 dates gives difference in days. How do I convert this number into months? Have tried many times but formula fails at certain conditions. Please help. Thank you. Regards, Saras Sara: Assuming you want to do it like this: Date 1: 1/15/06 Date 2: 3/14/06 Difference in months is 1 + 29 days. If Date 2 was 3/15/06, the difference would be 2. so: if (day('Date1') < day(...

how can I know that the option of "Obtain DNS server address automatically" have be set or checked by coding?
how can I know that the option of "Obtain DNS server address automatically" in Internet Protocol(TCP\IP) property have be set or checked by coding ? I need to judge it and change "Obtain DNS server address automatically" to "Use the following DNS server addresses"; Are there any api or other methods to get it? You can call GetAdaptersInfo(...). The DhcpEnabled member of IP_ADAPTER_INFO tells you if DHCP is enabled or not. AliR. "flyingco" <zhouyou3000@gmail.com> wrote in message news:1161669642.332731.240670@h48g2000cwc.googlegroups.com... >...

Help with VBA Code
I have the following as part of some VBA:- lLastRow = wks.Range("A1").End(xlDown).Row wks.Cells(lLastRow + 1, 1).Formula = "TOTAL VALUE" wks.Cells(lLastRow + 1, 2).Formula = "=COUNTA(B2:B&1LastRow)" The first line ascertains the last row that has a value. The second line sets a formula in the last row + 1 (i.e. sets value to TOTAL VALUE). The third line is intended to use the COUNTA function to count all rows from B2 to the last row. When I run this I get, Run Time error 1004, Application defined or object defined error. Basically,...

Document no longer exists in originating module
When I click on any links (Document Number, Voucher/Payment Number) in Payabled Transaction Inquiry - Vendor screen for a specific transaction, the error message poped up "Document no longer exists in originating module." When I tried for other transactions, there was no error message. How do I fix this issue? Thanks! The first thing I'd do is run Checklinks for Payables. If that doesn't fix it then I suspect the originating document was somehow purged or is corrupted. Good luck, Frank Hamelly, MCP-GP NOVA Solutions LLC Melbourne, FL ...

UPC code
I am installing RMS 2.0. I have a 10K product database that i need to import. 20% of the products have UPC-A and E digit codes with the last digit (check digit) missing. can i still use the UPC codes with the check digit missing if i program my scanner to only look at the first 11 digits of the bar code. Alterntively, could i just have the bar code reader pull out the manufacturer code and item number to do the look up. any guidance the could be provided would be helpful. -- Alex Dixon IT WSE Alex, yes you can use just the first 11 digits of the barcode. As you stated, progr...

how to hide the original message received
in outlook the e mail messagfe appears when i clik on the inbox...i dont want the actual message to open since it mayu have virus etc..wher to i go to settings to have only thje senders address etc apper and then i can choose myself if i want to open it. i have looked thru all my options but cant seem to find wher e it is to do what i want..thanks are you talking about the reading pane? View > reading pane > off also uncheck auto preview if it's on. "BILLY2BS" <BILLY2BS@discussions.microsoft.com> wrote in message news:CD1719B0-1F70-4B41-A608-54744F0FC456@micro...

Clicking a column by means of code
private void makeStockList() { listView1_ColumnClick(listView1, ? listView1.ColumnHeaderCollection[5]) ? ; // more code } #region Sorting columns. private void listView1_ColumnClick(object sender, ColumnClickEventArgs e) { this.listView1.ListViewItemSorter = new ListViewItemComparer(e.Column); listView1.Sort(); } #endregion Re the above, I want to click column header 5 by means of code. What I have between ?? doesn't work. Which parameter would work? Za...

View source code for CRM pages...
Hi.. I'm sure I've found how to do this previously, but if anyone can prompt my memory, I would appreciate it. I need to see the source code for pages generated through CRM. Simply setting AppMode to off allows me to view source on the main pages, but not on any of the entity pages. If anyone can help, that would be great. Cheers Chris "Chris Ericoli" <cericoliNOspm@removethisfamill.com.au> schrieb im Newsbeitrag news:OnL$5U4nEHA.4056@TK2MSFTNGP09.phx.gbl... > I'm sure I've found how to do this previously, but if anyone can prompt my > memory, I...

Saving files to originating PC using Citrix
Some of my remote users need to save tab delimited files creating using Great Plains printing function to their local computers. What are the keys to doing this? ...

Please please help!! Weird coding issue
Hi, I have a button that when pressed asked to select a worksheet and select email addresses, when the email addresses have been selected it will then email that particular user. Columns A,B and C needs to be hidden but when I hide these columns I get a mismatch error, if the columns stay visable it works? please help this is very fustrating!! Mis match error 13 Sub MAIL_PIP() Dim Response As String Dim DefaultFolder As String, DefaultFileName As String Dim FileToSave Dim OutApp As Object 'this emails operations manager Dim OutMail As Object Dim strbody As String ...