|
Thanks, I was allready overriding OnCtlColor and just needed to add an else if. Worked like a champ.
Bill
|
|
|
|
|
I'm trying to create a single instance standalone dialog box with the SetforegroundWindow. Should I register the class and use Findwindow.
Thanks
|
|
|
|
|
|
to ensure your application runs only one instance
on your InitInstance()
{
CreateMutex(NULL,false,"ur app");
if(GetLastError()=ERROR_ALREADY_EXISTS)
{
//alredy there is an instance present
//return/something u want to do here
}
}
just Look the previous messageboard entries
i told it a thousand times..!!!!
Renjith-The CPian.
|
|
|
|
|
This error is popping up sporadically upon calling CFile::Flush(). Does anyone know what might cause this call to fail sporadically with this error message?
"an unknown error occurred while accessing an unnamed file"
: Dean 'Karnatos' Michaud
|
|
|
|
|
I've seen that error -- You get that error if the file was not opened successfully or some permissions are incorrect.
|
|
|
|
|
I've created an array of unsigned chars as a parity table. During program initialization, I originally memset the array to all zeros. In the same init sequence, I set elements of the array to one to signify that the parity bit should be set for that particular value.
// in header file
#define RADAR_PARITYTBLSZ 4096
unsigned char RadarParityTable[RADAR_PARITYTBLSZ];
// in .C file
// Initialize parity table for 12 bit radar msgs and 1 bit of parity
memset(&RadarParityTable, 0, sizeof(RadarParityTable));
for(i = 0; i < RADAR_PARITYTBLSZ; i++)
if(ComputeParity(i) == 0) // this returns 0 if value of i is even
RadarParityTable[i] = 1;
The problem is that the last element of the array, in this case [4095], (the array is 4096 bytes in size, is mysteriously set to 0x20 instead of 1. I'm using odd parity so the parity for a value of 0xfff or 4095 -- 12 binary bits set means add one to it to make it odd.
I set a breakpoint right after the code above in the init sequence and Quickwatch says ALL of the values are zero. Later when I compare parity to the parity table in another module and use quickwatch, the value for that element is 0x20. The only way I was able to fix this was to increase the size of the array by 1 to 4097, initialize the first 4096 elements the same as before, and then all of the values in the array were correct even the last one. I even tried adding this line of code below in the init sequence but it didn't work.
RadarParityTable[RADAR_PARITYTBLSZ-1] = 1;
Any ideas why it was set to hex 0x20.
|
|
|
|
|
Nothing in the code that you show should have this result.
Why not use a data breakpoint in the debugger to see when the element is being overwritten?
Data breakpoints are set with Edit / BreakPoints and then selecting the Data tab.
Enter as the expression: RadarParityTable[4095]
Best regards,
John
|
|
|
|
|
I'll try that tomorrow. I'm at home now.
|
|
|
|
|
You probably have another array on the atck which is writing beyond its bounds. Take a look at the other vars declared next to your array.
Roger Allen
Sonork 100.10016
If I had a quote, it would be a very good one.
|
|
|
|
|
You were right and John Barton's suggestion helped me identify the problem though I still have to find out why. Apparently, that element in the array gets overwritten when I'm using strtok() on some other data. I'm not sure if it's because I'm using strtok in a thread or if I'm doing some bad pointer arithmetic.
I use strtok on a buffer and then later do...
*(p - 1) = ' ';
because I need to place spaces back into the buffer so that I can look for two spaces. It could be that statement. Anyways, thanks for the help, guys.
|
|
|
|
|
*(p - 1) = ' ';
will put a space character in the byte imedieatly preceeding the location pointed to by p. If p is a pointer to the location after your buffer, the last character of your buffer will become a 0x20 (space character).
|
|
|
|
|
Yes. That space however is going to the end of the wrong array, RadarParityTable. I have to parse another buffer, a file header, and treat the data differently when it encounters two spaces. Because strtok puts a 0x00 or '\0' at the end of each substring where the token exists, the data will be in EBCDIC when written to disk, I had to replace the spaces that strtok put into it. So, I did as you say put a space preceding the spot where strtok found the next substring of data.
I must be corrupting that memory somehow, though boundschecker active mode is not catching it. Its funny though that changing the size of the RadarParityTable from 4096 to 4097 fixed the problem.
|
|
|
|
|
JohnnyG wrote:
memset(&RadarParityTable, 0, sizeof(RadarParityTable));
to
memset(RadarParityTable, 0, sizeof(RadarParityTable));
Did you corrected this ???
Hth....;)
Ramu
|
|
|
|
|
Sorry, I didn't answer. I did not get to it but I believe that when I don't put the address of operator (&) it says something about parameter 1 not being right. That's why I used &RadarParityTable. I'll check again if I have time tomorrow. I know that parameter 1 should be a void pointer. Thanks
|
|
|
|
|
What error message does it exactly give ???
Using '&' is not correct.
Thanks,
Ramu
|
|
|
|
|
You were right Ramu. I had gotten this msg earlier:
'memset' : actual parameter is not a pointer : parameter 1
but that was for a structure. So, when I coded the statement for an array I used the same technique. Now, I see the errors of my way.
|
|
|
|
|
BTW, The way I'm doing it now doesn't give me any warnings and when I breakpoint after the memset, the entire array is equal to zeroes.
|
|
|
|
|
I fixed it. Thanks, everybody. It turns out that on the very first call to strtok and all subsequent calls, I was placing the '\0' that strtok appends to each substring with a space. However, on the first call to strtok, there is no space (my token) before it, and thus I was placing a space into a memory address where my other array's end element existed.
|
|
|
|
|
Hey everybody, I put a post out about my word automation not working. I haven't been able to get past the Link Error so I tried something different. Now, I have this function which puts a button (with a bitmap) onto MS Word. As you can see, I create it dynamically. Now, what I was wondering, how can I capture the event when this button is pressed? I am trying to do an Advise but it doesn't seem to be doing what I want it to do??? I have pasted the header file for the event sink and the actual function which does the Advise. Any ideas? Anything come to mind? Do you think I am making this too complicated and have a better way to go at it? Just let me know, I am knew to COM/ATL/OLE development...
======================================================================
header file wordeventsink.h:
#if !defined(AFX_WORDEVENTSINK_H__F45A8330_C1E9_11D2_A0C4_0080C7F3B56B__INCLUDED_)
#define AFX_WORDEVENTSINK_H__F45A8330_C1E9_11D2_A0C4_0080C7F3B56B__INCLUDED_
/*----------------------------------------------------------------------------*/
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
/*----------------------------------------------------------------------------*/
//#pragma warning (disable:4146)
//#import "mso97.dll"
//#pragma warning (default:4146)
//#import "vbeext1.olb"
//#import "msword8.olb" rename("ExitWindows", "WordExitWindows")
#pragma warning (disable:4146)
#import "C:\Program Files\Common Files\Microsoft Shared\Office10\mso.dll"
#pragma warning (default:4146)
#import "C:\Program Files\Common Files\Microsoft Shared\VBA\VBA6\vbe6ext.olb"
#import "C:\Program Files\Microsoft Office\Office10\MSWORD.olb" rename("ExitWindows", "WordExitWindows")
#include "ConnectionAdvisor.h"
class CTestDlg;
/*----------------------------------------------------------------------------*/
const IID IID_IWordAppEventSink = __uuidof(Word::ApplicationEvents);
const IID IID_IWordDocEventSink = __uuidof(Word::DocumentEvents);
const IID IID_IPSISaveExit = __uuidof(Office::_CommandBarButtonEvents);
/*----------------------------------------------------------------------------*/
class CWordEventSink : public CCmdTarget
{
DECLARE_DYNCREATE(CWordEventSink)
public:
CWordEventSink();
virtual ~CWordEventSink();
BOOL Advise(IUnknown* pSource, REFIID iid);
BOOL Unadvise(REFIID iid);
void SetLauncher(CTestDlg* pWordLauncher);
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CWordEventSink)
public:
virtual void OnFinalRelease();
//}}AFX_VIRTUAL
protected:
// Generated message map functions
//{{AFX_MSG(CWordEventSink)
// NOTE - the ClassWizard will add and remove member functions here.
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
// Generated OLE dispatch map functions
//{{AFX_DISPATCH(CWordEventSink)
afx_msg void OnAppStartup();
afx_msg void OnAppQuit();
afx_msg void OnAppDocumentChange();
afx_msg void OnDocNew();
afx_msg void OnDocOpen();
afx_msg void OnDocClose();
afx_msg void PSISaveAndExit();
//}}AFX_DISPATCH
DECLARE_DISPATCH_MAP()
DECLARE_INTERFACE_MAP()
private:
CConnectionAdvisor m_AppEventsAdvisor;
CConnectionAdvisor m_DocEventsAdvisor;
CConnectionAdvisor m_BarEventsAdvisor;
CTestDlg* m_pWordLauncher;
};
/////////////////////////////////////////////////////////////////////////////
//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.
#endif // !defined(AFX_WORDEVENTSINK_H__F45A8330_C1E9_11D2_A0C4_0080C7F3B56B__INCLUDED_)
======================================================================
function in testdlg.cpp:
void CTestDlg::OnOK()
{
try
{
HRESULT hr = m_pWord.CreateInstance(__uuidof(Word::Application));
ASSERT(SUCCEEDED(hr));
m_pDoc = m_pWord->Documents->Add();
BOOL Res = m_WordEventSink.Advise(m_pWord, IID_IWordAppEventSink);
ASSERT(Res == TRUE);
Res = m_WordEventSink.Advise(m_pDoc, IID_IWordDocEventSink);
ASSERT(Res == TRUE);
m_pWord->Visible = VARIANT_TRUE;
COleVariant covTrue((short) TRUE),
covFalse((short) FALSE),
covOptional((long)DISP_E_PARAMNOTFOUND, VT_ERROR);
Office::_CommandBarsPtr oBars = m_pWord->GetCommandBars();
// Office::_CommandBarsPtr oBars;
// m_pWord->get_CommandBars(&oBars); // New CommandBars
VARIANT vName;
vName.vt = VT_BSTR;
vName.bstrVal = SysAllocString(L"PSI");
VARIANT vPosition;
vPosition.vt = VT_I2;
vPosition.iVal = 1; // 4 = Floating; 0 = top;
VARIANT vTemp;
vTemp.vt = VT_BOOL;
vTemp.boolVal = VARIANT_TRUE;
// Add new bar to the command bars collection
Office::CommandBarPtr oNewBar = oBars->Add(vName, vPosition, covOptional, vTemp);
// oBars->raw_Add(vName, // const Variant Name
// vPosition, // const Variant Position
// vTemp, // const Variant (replace)MenuBar
// vTemp, // const Variant Temporary
// &oNewBar
// );
//
oNewBar->Visible = VARIANT_TRUE;
// oNewBar->put_Visible(TRUE);
// Get the collection (now empty) of controls on the new commandbar
Office::CommandBarControlsPtr oNewControls = oNewBar->GetControls();
// oNewBar->get_Controls(&oNewControls);
VARIANT vType;
vType.vt = VT_I4;
vType.lVal = (long)1;
Office::CommandBarControlPtr oNewControl = oNewControls->Add(vType, covOptional, covOptional, covOptional, vTemp);
// Office::_CommandBarButtonPtr m_pButton; // Office XP - note leading underscore
// oNewControls->raw_Add(vType, // Type = msoControlButton
// covOptional, // Id
// covOptional, // Parameter
// covOptional, // Before
// covTrue, // Temporary
// &oNewControl
// );
//
Office::_CommandBarButtonPtr oNewButton (oNewControl);
m_pButton = oNewButton;
Res = m_WordEventSink.Advise(m_pButton, IID_IPSISaveExit);
ASSERT(Res == TRUE);
// m_pButton->Style(3);
// m_pButton->Caption(SysAllocString(L"PSI Save & Exit"));
m_pButton->Visible = VARIANT_TRUE;
m_pButton->Enabled = TRUE;
m_pButton->
// m_pButton->put_Style(Office::msoButtonIconAndCaption); // msoButtonIconAndCaption
// m_pButton->put_Caption(OLESTR("PSI Save & Exit"));
// m_pButton->put_TooltipText(OLESTR("This is a new button"));
// m_pButton->put_Visible(VARIANT_TRUE);
// m_pButton->put_Enabled(VARIANT_TRUE);
OpenClipboard(); // Reserve clipboard for this program
CBitmap MyBitmap;
MyBitmap.LoadBitmap(IDB_BITMAP1); // A Bitmap you drew in the
// Resource Editor
HBITMAP MyBitmapHandle = (HBITMAP)MyBitmap; // Cast it to a HBITMAP
SetClipboardData(CF_BITMAP, MyBitmapHandle);
CloseClipboard(); // Free clipboard so PasteFace() can use it
m_pButton->PasteFace();
GetDlgItem(IDOK)->EnableWindow(FALSE);
}
catch (_com_error& ComError)
{
DumpComError(ComError);
}
}
|
|
|
|
|
You have to advise the button events (_CommandBarButtonEvents) from m_pButton and add event handlers to the sink map.
Hth,
Ramu
|
|
|
|
|
I created a stand alone MFC dialog box. After debugging I noticed that m_hWnd is always NULL. I'm trying to get the handle to the dialogbox.
Thanks
|
|
|
|
|
This handle will be null until you create the dialog with Create or indirectly with DoModal ---having the CDialog constructed does not suffice.
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
I am receiving data from a socket server (QNX based) into a VC++ DLL. the data is in the format
struct Data {
short num;
unsigned long value;
char name[33];
}
I am receiving a message containing large numbers of these data strucutres. I can store them fine in my DLL, i have adjusted the byte packing and everything works great. Now, I have to move the data from my DLL into Visual Basic. I have read competing articles (by microsoft) on the proper way to fill a UDT Array passed from vb. I have tried many things including the use of a Type Library.
I would like to pass in a reference to the UDT Array from VB to C++ DLL, and populate it with the data i received from the QNX process. I am having trouble with both fixed strings and variable length strings. Please help. Please Please Please help. This has gotten very frustrating..
Any Help would be greatly appreciated.
Ryan Baillargeon
Software Specialist
Fuel Cell Technologies Inc.
|
|
|
|
|
I am currently having trouble with MFC
What I am trying to accomplish is as follows; When a user double clicks the mouse on a section of the dialogue window a bitmap would be displayed at the location of the doubleclick.
The Problem; I cant seem to find any code that would allow me to do this. All code I have found either loads a bitmap when the window is created or will not funcion in a dialogue window.
This is my first post here at TheCodeProject. If I did not post in the right place or did not follow a proper convention please let me know so I can remedy it.
Thanks,
Eric
|
|
|
|