Any Guru can figure out how to diisplay C++ MFC CDialog-based control in Excel from Excel command?

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



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;
}
.



Relevant Pages

  • Re: Passing arguments from VBA to DLL
    ... I noticed that foo didn't work internally as I expected and added ... XLL is a special programming model for EXCEL. ... problems when calling the DLL from VBA functions or macros. ...
    (microsoft.public.excel.programming)
  • Re: Have anyone ever called solver.dll
    ... Does anyone have the experiance on calling the solver.dll of excel and can give some demo example? ... What you want to implement with that dll? ...
    (comp.lang.labview)
  • Time Triggered Events
    ... I am looking to have excel perform certain events based on time. ... At 8:00:00 AM every morning I want excel to display a message box that ... My problem is that excel time doesnt automatically refresh/update so I ... cannot simply create a function checking the time and then calling ...
    (microsoft.public.excel.programming)
  • RE: Table of data on ERD
    ... You have designed your great ER diagram with Visio ... Open or create an Excel document and create two rows of data, ... will be displayed as to how you want to display the data next to your Entity. ... Use Microsoft's powerful connection features as you need. ...
    (microsoft.public.visio.general)
  • All words and Symbols of keybord should be added to Auto Shapes
    ... Suggestions are both for Word and Excel where applicable. ... Transpose should have an extra facility to transpose the selected cells ... display begins in the second line and therefore we cannot see row name A, B, ... And more in a single selection at a time, then there will be no problem. ...
    (microsoft.public.excel.misc)