T
ThirstyForKnowledge
Here is a problem that I've been battling with incremenatlly for the
past month with almost getting to the final solution. I'm aiming to
get to a point where I select a menu-item from Excel, therby
triggering a call to a command within the xll compiled code. This
part was easily achievable. Yet the reason that I approach you ou
there Gurus is because in the function that is called I would like to
display a CDialog-based dialog control. I managed to accomplish that
by building an MFC extension dll which contained a function that, when
called, displays a CDialog-based dialog from within the dll. The
external calling code merely calls the dll interface function and
passes one argument in that call. That argumetn is the parent window
of the dll-using external code. Having done that with two projects,
mainly MFC extension dll and MFC exe project ( the code using the
dll), I turned to do it with Excel. This time the Excel is the code
calling the xll functiuon (instead of dll). Yet when calling a
command from Excel, I litteraly pass zero arguments, unlike the case
just described above. As such, assuming that the method above of
displaying the dialog should also work in Excel, I used the Excel C
API function xlGetHWnd and then I casted it to CWnd. It seems to me
that the casting went successfuly, since I managed to confirm after
casting that the caption (i.e., through GetWindowTex()) is indeed the
Excel caption and the same applieds to the rectangle dimension.
However, when I use the CWnd pointer to call that method which creates
the Dialog and displays it, I get an error message. It is a Debug
Assertion type of
error specifying line 22 in afxwin1.inl
Pleasse note that line 22 in afxwin1.inl is the middle line of the
following function:
_AFXWIN_INLINE HINSTANCE AFXAPI AfxGetResourceHandle()
{ ASSERT(afxCurrentResourceHandle != NULL); //this is the
line where
code fails
return afxCurrentResourceHandle; }
CAN ANYONE SHED SOME LIGHT ON THIS ISSUE AND TELL ME WHAT DO I DO
WRONG -- WHERE IS MY FIXATION? DID I MAKE THE WRONG ANALOGY WHEN
HAVINF SOMETHING WORK SUCCESSFULY IN THE DLL WORLD AND EXPECTING IT TO
HAPPEN IN THE XLL WORLD? I
THANK YOU IN ADVANCE FOR READING. YOUR HELP IS ALWAYS APPRECIATED.
Here is the code that tries to display the dialog:
int __stdcall ExampleCmdExport(void)
{
cpp_xloper cpp_hwnd; //cpp_xloper is an xloper class (easier to work
with)
cpp_hwnd.Excel(xlGetHwnd); // this line uses the xlGetHwnd C API
function
int lhwnd=(int)(cpp_hwnd); /// converting the returned value to int
get_hwnd_struct eproc_param = {lhwnd, 0}; // structure helping to
get the handle of Exel
/// assume the following line works for me -- indeed it worked for
me
EnumWindows((WNDENUMPROC)get_hwnd_enum_proc,
(LPARAM)&eproc_param);
/// the full_handle in next line of code is what we are looking
for
CWnd * pParent = CWnd::FromHandle(eproc_param.full_handle);
CString st;
pParent->GetWindowText(st); // this is just a test that produces what
we expect for
// next line instantiates an object from simple class that is
supposed to display dialog
// look below for implemenation of that class
ExcelTrialDialog TestDLG(pParent);
return 1;
}
class ExcelTrialDialog : public CObject
{
public:
SecondDialog * DLG; /// SecondDialog is a CDialog derived class
ExcelTrialDialog(CWnd * pParent);
virtual ~ExcelTrialDialog();
};
ExcelTrialDialog::ExcelTrialDialog(CWnd * pParent)
{
DLG=new SecondDialog(pParent);
DLG->DoModal();
}
ExcelTrialDialog::~ExcelTrialDialog()
{
delete DLG;
}
past month with almost getting to the final solution. I'm aiming to
get to a point where I select a menu-item from Excel, therby
triggering a call to a command within the xll compiled code. This
part was easily achievable. Yet the reason that I approach you ou
there Gurus is because in the function that is called I would like to
display a CDialog-based dialog control. I managed to accomplish that
by building an MFC extension dll which contained a function that, when
called, displays a CDialog-based dialog from within the dll. The
external calling code merely calls the dll interface function and
passes one argument in that call. That argumetn is the parent window
of the dll-using external code. Having done that with two projects,
mainly MFC extension dll and MFC exe project ( the code using the
dll), I turned to do it with Excel. This time the Excel is the code
calling the xll functiuon (instead of dll). Yet when calling a
command from Excel, I litteraly pass zero arguments, unlike the case
just described above. As such, assuming that the method above of
displaying the dialog should also work in Excel, I used the Excel C
API function xlGetHWnd and then I casted it to CWnd. It seems to me
that the casting went successfuly, since I managed to confirm after
casting that the caption (i.e., through GetWindowTex()) is indeed the
Excel caption and the same applieds to the rectangle dimension.
However, when I use the CWnd pointer to call that method which creates
the Dialog and displays it, I get an error message. It is a Debug
Assertion type of
error specifying line 22 in afxwin1.inl
Pleasse note that line 22 in afxwin1.inl is the middle line of the
following function:
_AFXWIN_INLINE HINSTANCE AFXAPI AfxGetResourceHandle()
{ ASSERT(afxCurrentResourceHandle != NULL); //this is the
line where
code fails
return afxCurrentResourceHandle; }
CAN ANYONE SHED SOME LIGHT ON THIS ISSUE AND TELL ME WHAT DO I DO
WRONG -- WHERE IS MY FIXATION? DID I MAKE THE WRONG ANALOGY WHEN
HAVINF SOMETHING WORK SUCCESSFULY IN THE DLL WORLD AND EXPECTING IT TO
HAPPEN IN THE XLL WORLD? I
THANK YOU IN ADVANCE FOR READING. YOUR HELP IS ALWAYS APPRECIATED.
Here is the code that tries to display the dialog:
int __stdcall ExampleCmdExport(void)
{
cpp_xloper cpp_hwnd; //cpp_xloper is an xloper class (easier to work
with)
cpp_hwnd.Excel(xlGetHwnd); // this line uses the xlGetHwnd C API
function
int lhwnd=(int)(cpp_hwnd); /// converting the returned value to int
get_hwnd_struct eproc_param = {lhwnd, 0}; // structure helping to
get the handle of Exel
/// assume the following line works for me -- indeed it worked for
me
EnumWindows((WNDENUMPROC)get_hwnd_enum_proc,
(LPARAM)&eproc_param);
/// the full_handle in next line of code is what we are looking
for
CWnd * pParent = CWnd::FromHandle(eproc_param.full_handle);
CString st;
pParent->GetWindowText(st); // this is just a test that produces what
we expect for
// next line instantiates an object from simple class that is
supposed to display dialog
// look below for implemenation of that class
ExcelTrialDialog TestDLG(pParent);
return 1;
}
class ExcelTrialDialog : public CObject
{
public:
SecondDialog * DLG; /// SecondDialog is a CDialog derived class
ExcelTrialDialog(CWnd * pParent);
virtual ~ExcelTrialDialog();
};
ExcelTrialDialog::ExcelTrialDialog(CWnd * pParent)
{
DLG=new SecondDialog(pParent);
DLG->DoModal();
}
ExcelTrialDialog::~ExcelTrialDialog()
{
delete DLG;
}