Re: How can I call MFC functions from Perl




"Sankaran" <psankarv@xxxxxxxxx> wrote in message
news:1121834797.922460.149360@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
> Hello,
>
> How can I call MFC functions from Perl? Which module / method I should
> select? Inline:C ? Inline:CPP ? XS ? or SWIG?
>

If no-one here knows, ask on the Inline mailing list. The question seems to
have been raised on that list only once - and then not answered. But that
was some time ago and there might now be someone there who knows the answer.

I personally would not even attempt it with Inline::C - but Inline::CPP
could be worth trying if you've got it installed and functioning correctly.

I found the following code in a book and tried to compile it:

--- start SimpleMFCApp.cpp ----

#include <afxwin.h>

//Window class definition
class COurWnd : public CFrameWnd
{
};
// Application class definition
class COurApp : public CWinApp
{
public:
virtual BOOL InitInstance();

private:
COurWnd* GetMainWindow() {return static_cast<COurWnd*>(m_pMainWnd);}
};

//Function to create an instance of the main window
BOOL COurApp::InitInstance(void)
{
//Construct an object of our C++ window class
m_pMainWnd = new COurWnd;

//Call Create() to create the underlying window
GetMainWindow()->Create(NULL, _T("Our Simple Window"));

//Call ShowWindow() to display the window
GetMainWindow()->ShowWindow(m_nCmdShow);
return TRUE;
}

//Application object definition at global scope
COurApp AnApplication;

--- end SimpleMFCApp.cpp ----

But when I try to compile it I always get linking errors - no matter what I
try to link to. Closest I got to getting it to compile was by linking to
libcmt.lib with:

cl /MT SimpleMFCApp.cpp

That produced:

-----------------------------------
Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 13.00.9466 for 80x86
Copyright (C) Microsoft Corporation 1984-2001. All rights reserved.

SimpleMFCApp.cpp
Microsoft (R) Incremental Linker Version 7.00.9466
Copyright (C) Microsoft Corporation. All rights reserved.

/out:SimpleMFCApp.exe
SimpleMFCApp.obj
libcmt.lib(crt0.obj) : error LNK2019: unresolved external symbol _main
referenced in function _mainCRTStartup
SimpleMFCApp.exe : fatal error LNK1120: 1 unresolved externals
----------------------------------

Unfortunately the only advice I could find on google involved clicking on
options within the Visual Studio GUI - which just makes me wanna throw up. I
couldn't find any help in terms of command line options. Do you know how
that app could be compiled from the command line ?

Or am I supposed to build a dll rather than executable ? I did find that by
removing the last line of code from SimpleMFCApp.cpp I was able to build a
dll by running:

cl /LD SimpleMFCApp.cpp

Do you want to access (from perl) an MFC dll ? Is that what you are trying
to do ?

I spent half an hour or so trying to access my SimpleMFCApp.dll using
Inline::CPP, but could not get past the error:

F:\vsnet\Vc7\atlmfc\include\afxv_w32.h(18) : fatal error C1189: #error :
WINDOWS.H already included. MFC apps must not #include <windows.h>

I don't know why that's happening yet (not sure whether it's something I'm
doing, or whether it's something that Inline::C does - and I've run out of
time for tonight :-(


I don't know where one would ask (anything) about swig, but you might find
out something about the possibility of mixing MFC and XS from the perl-xs
mailing list. See http://lists.perl.org/index.cgi .

Cheers,
Rob



.



Relevant Pages

  • Re: Managed VC++
    ... and with VC.NET it's easy to mix the two, hard code the form if you give it a ... I'm currently reading Jim Adams book on advanced ... this way, the DX functions / classes I create can be used with my Win32, MFC ... this code you're writing now may not compile then without a major overhaul. ...
    (microsoft.public.win32.programmer.directx.managed)
  • Re: daylight saving time impact on C library
    ... We have a Visual Studio 6 C++ application that is built using a compile ... Will we need to rebuild the exe, or does MFC use Windows API that can take ... advantage of patched DLLs on the OS? ...
    (microsoft.public.dotnet.languages.vc)
  • Re: CF faster than MFC?
    ... MFC and basic Win32 compile to machine code at compile time. ... it's possible to write an MFC app that is slower than a CF ...
    (microsoft.public.pocketpc.developer)
  • Re: 64b Windows - crashes not detected
    ... compile and illustrate the differences you're experiencing? ... Drop this into the main 'view' cpp file of a new MFC application (just before 'OnDraw' ... MTest *m_mat; ... RoomTest testRoom; ...
    (microsoft.public.vc.mfc)
  • Re: upgrade from vc++ 6.0 to .net 2005 ?
    ... Will I be able to compile this old mfc code as is? ... (The mix of ace and vc++ 6.0 is pretty bad anyway. ... The MFC libraries have changed very little. ...
    (microsoft.public.vc.mfc)