Thread: C++ console application works; Excel crashes when using the same code.

  1. #16
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Code::Blocks is hailed as a great IDE (first link). Of course, Visual Studio isn't bad either.
    But I'd try both and stick to the one I like most.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  2. #17
    Registered User
    Join Date
    Dec 2010
    Location
    Cordoba, Argentina
    Posts
    27
    Elysia/Codeplug:

    Thanks for your quick answers .... I'm already downloading these IDEs ...

    After that I'll retry and let you know how did all go ...

    Many thanks and BRs,

    Lucas

  3. #18
    Registered User
    Join Date
    Dec 2010
    Location
    Cordoba, Argentina
    Posts
    27

    Unhappy

    Hi ...

    I've downloaded both code::blocks and wxDec-C++ but compilation failed with both of them ...

    Same error as before ...

    - Output Codeblocks:
    -------------- Clean: default in IP_FNC ---------------

    Cleaned "IP_FNC - default"

    -------------- Build: default in IP_FNC ---------------

    Compiling: ipfnc.cpp
    Linking dynamic library: ipfnc.dll
    .objs\ipfnc.o:ipfnc.cpp.text+0x99): undefined reference to `SysAllocStringByteLen@8'
    collect2: ld returned 1 exit status
    Creating library file: libipfnc.dll.a
    Process terminated with status 1 (0 minutes, 1 seconds)
    1 errors, 0 warnings
    - Output xwDev-C++:
    Compiler: Default GCC compiler
    Building Makefile: "d:\datos\doc\tech\c++\excel\ipfnc\Makefile.wi n"
    Executing make clean
    rm -f "Default Profile/ipfnc.o" "Default Profile/ipfnc.dll"

    g++.exe -c ipfnc.cpp -o "Default Profile/ipfnc.o" -I"C:/Archivos de programa/Dev-Cpp/lib/gcc/mingw32/3.4.5/include" -I"C:/Archivos de programa/Dev-Cpp/include/c++/3.4.5/backward" -I"C:/Archivos de programa/Dev-Cpp/include/c++/3.4.5/mingw32" -I"C:/Archivos de programa/Dev-Cpp/include/c++/3.4.5" -I"C:/Archivos de programa/Dev-Cpp/include" -I"C:/Archivos de programa/Dev-Cpp/" -I"C:/Archivos de programa/Dev-Cpp/include/3rdparty/wx/plotctrl" -I"C:/Archivos de programa/Dev-Cpp/include/3rdparty/wx/sheet" -I"C:/Archivos de programa/Dev-Cpp/include/3rdparty/wx/treemultictrl" -I"C:/Archivos de programa/Dev-Cpp/include/3rdparty/wx/things" -I"C:/Archivos de programa/Dev-Cpp/include/3rdparty/wx" -I"C:/Archivos de programa/Dev-Cpp/include/3rdparty" -I"C:/Archivos de programa/Dev-Cpp/include/common/wx/msw" -I"C:/Archivos de programa/Dev-Cpp/include/common/wx/generic" -I"C:/Archivos de programa/Dev-Cpp/include/common/wx/fl" -I"C:/Archivos de programa/Dev-Cpp/include/common/wx/gizmos" -I"C:/Archivos de programa/Dev-Cpp/include/common/wx/html" -I"C:/Archivos de programa/Dev-Cpp/include/common/wx/mmedia" -I"C:/Archivos de programa/Dev-Cpp/include/common/wx/net" -I"C:/Archivos de programa/Dev-Cpp/include/common/wx/ogl" -I"C:/Archivos de programa/Dev-Cpp/include/common/wx/plot" -I"C:/Archivos de programa/Dev-Cpp/include/common/wx/protocol" -I"C:/Archivos de programa/Dev-Cpp/include/common/wx/stc" -I"C:/Archivos de programa/Dev-Cpp/include/common/wx/svg" -I"C:/Archivos de programa/Dev-Cpp/include/common/wx/xml" -I"C:/Archivos de programa/Dev-Cpp/include/common/wx/xrc" -I"C:/Archivos de programa/Dev-Cpp/include/common/wx" -I"C:/Archivos de programa/Dev-Cpp/include/common" -DBUILDING_DLL=1 -g3

    g++.exe -shared "Default Profile/ipfnc.o" -L"C:/Archivos de programa/Dev-Cpp/Lib" -g3 -Wl,--out-implib,"Default Profile/libipfnc.a" -o "Default Profile/ipfnc.dll"

    Creating library file: Default Profile/libipfnc.a
    Default Profile/ipfnc.o: In function `string_ex':
    d:/datos/doc/tech/c++/excel/ipfnc/ipfnc.cpp:48: undefined reference to `SysAllocStringByteLen@8'
    collect2: ld returned 1 exit status

    mingw32-make.exe: *** [Default] Error 1

    Execution terminated
    Compilation Failed. Make returned 2
    Am I missing any include header? What can be wrong then? I've read here (http://forum.imasters.com.br/index.p...retorna-texto/) that the 'oleauto.h' header must be included, and it's included, however it seams that there's something still missing somewhere ...

    Thanks in advance,

    Lucas

  4. #19
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    The library is oleaut32.lib if I'm reading MSDN correctly (it was on a Windows CE page, but), so you need to link that library with your code.

  5. #20
    Registered User Codeplug's Avatar
    Join Date
    Mar 2003
    Posts
    4,981
    You need to link against "liboleaut32.a", or "-loleaut32".

    gg

  6. #21
    Registered User
    Join Date
    Dec 2010
    Location
    Cordoba, Argentina
    Posts
    27

    Question

    Quote Originally Posted by tabstop View Post
    The library is oleaut32.lib if I'm reading MSDN correctly (it was on a Windows CE page, but), so you need to link that library with your code.
    Thanks, but, where do I get that library from? I was expecting to find it within wxDev-C++ or Codeblocks ... :-S

  7. #22
    'Allo, 'Allo, Allo
    Join Date
    Apr 2008
    Posts
    639
    In Code::Blocks you'd add 'oleaut32' (without quotes) to Project (menu)->Build Options->Linker Settings->Add
    ...where did all those posts come from, they weren't here when I started writing

  8. #23
    Registered User
    Join Date
    Dec 2010
    Location
    Cordoba, Argentina
    Posts
    27
    Quote Originally Posted by Codeplug View Post
    You need to link against "liboleaut32.a", or "-loleaut32".

    gg
    Thanks, I got to link the code with the library ... and it compiles now ...

    However, when calling the DLL from within VBA, Excel returns #VALUE! ... there is still something wrong with the types, either in the input parameters or in the return...

    As far as I've read, SysAllocStringByteLen returns a BSTR ANSI string ... If I'm not wrong, it should be UNICODE (2bytes per char, ain't it), since VBA sends out an UNICODE string. (SysAllocStringByteLen)

    I'll take a pause on this ...

    Many Thanks ...

    Lucas

  9. #24
    Registered User
    Join Date
    Dec 2010
    Location
    Cordoba, Argentina
    Posts
    27

    Thumbs down

    Hi,

    After downloading Code::blocks and wxDev-C++, I can no longer use successfully the DLL in Excel, even with a simple function.

    I had this simple function ...

    VBA:
    Code:
    Declare Function square Lib "d:/datos/doc/tech/c++/excel/ipfnc/ipfnc.dll" (ByVal x As Double) As Double
    DLL:
    Code:
    extern "C" __declspec( dllexport ) __stdcall double square(double x)
    {
          return 2*x;
    }
    ... which I would use to confirm correct communication between the DLL and Excel, but now, after compiling the code, this does no longer work ... :-(

    Could Code::blocks or wxDev-C++ be doing something different with respect to Dev-C++ 4.9.9.2? Before I could get this simple function to work ... :-S

  10. #25
    Registered User Codeplug's Avatar
    Join Date
    Mar 2003
    Posts
    4,981
    >> it should be UNICODE ... since VBA sends out an UNICODE string
    Nope. Go back and read the link in post #5, and then again with quotes in post #11.

    >> I can no longer use successfully the DLL in Excel
    You may of corrupted your MinGW installation by having 3 different versions installed at the same time - where one of them is in C:\MinGW - or more than one of them installed on top of each other. Or it may just be that you're not using correct build options.

    You could try uninstalling all 3 and reinstall just one.

    Or give Visual Studio Express a try: https://www.microsoft.com/express/Do...010-Visual-CPP

    gg

  11. #26
    Registered User
    Join Date
    Dec 2010
    Location
    Cordoba, Argentina
    Posts
    27
    >> it should be UNICODE ... since VBA sends out an UNICODE string
    Nope. Go back and read the link in post #5, and then again with quotes in post #11.

    >> I can no longer use successfully the DLL in Excel
    You may of corrupted your MinGW installation by having 3 different versions installed at the same time - where one of them is in C:\MinGW - or more than one of them installed on top of each other. Or it may just be that you're not using correct build options.
    Ok, I'm trying to do the simplest code ...

    VBA:
    Code:
    Public Declare Function mult Lib _
        "d:\datos\doc\tech\c++\excel\ipfnc_dll\ipfnc.dll" _
        (ByVal x As Integer) As Integer
    C++:
    Code:
    extern "C" __declspec( dllexport ) __stdcall short mult(short x);
    short mult(short x)
    {
          return 2*x;
    }
    But not even with this one I'm being able to get it to work ... when I do '=mult(A3)' (where A3=2, expecting a 4) from Excel i get #VALUE!.

    The compilation shows no error.

    -------------- Clean: default in IP_FNC ---------------

    Cleaned "IP_FNC - default"

    -------------- Build: default in IP_FNC ---------------

    Compiling: ipfnc.cpp
    Linking dynamic library: ipfnc.dll
    Creating library file: libipfnc.dll.a
    Output size is 133.87 KB
    Process terminated with status 0 (0 minutes, 0 seconds)
    0 errors, 0 warnings
    Am I missing something? I'm using Codeblocks 10.05 standard installation obtained from codeblocks-10.05mingw-setup.exe. Console applications do compile well and execute as expected...

    Sorry for being this annoying with this simple case ... :-S

    Thnx,

    Lucas

  12. #27
    Registered User Codeplug's Avatar
    Join Date
    Mar 2003
    Posts
    4,981
    What is the full command line for the compile/link?

    gg

  13. #28
    Registered User Codeplug's Avatar
    Join Date
    Mar 2003
    Posts
    4,981
    You may need "--add-stdcall-alias" added to your linker flags.
    Or "-Wl,--add-stdcall-alias" to your compiler flags.

    gg

  14. #29
    Registered User
    Join Date
    Dec 2010
    Location
    Cordoba, Argentina
    Posts
    27
    Quote Originally Posted by Codeplug View Post
    You may need "--add-stdcall-alias" added to your linker flags.
    Or "-Wl,--add-stdcall-alias" to your compiler flags.

    gg
    Yeap ... "-Wl,--add-stdcall-alias" did the trick ... now I can call the simple function from Excel and I got a result ...

    Now I'm going back to the old BSTR problem ...

    Thanks!

    Lucas

    pd: BTW, if possible, could you provide a link showing some info on "-Wl,--add-stdcall-alias": I really do not know what are they for ... :-P

  15. #30
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    Options - Untitled

    EDIT: Okay the "let the forum use the page title as the name of the link" tactic didn't work so well there. That's a link to the ld manual. (Anything after -Wl is an option that gets passed to the linker straight.)

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Not sure how this simple code works
    By metros in forum C Programming
    Replies: 8
    Last Post: 02-09-2010, 06:22 PM
  2. Subject:How to create a C# console application?
    By Adock in forum C# Programming
    Replies: 5
    Last Post: 09-03-2008, 05:58 PM
  3. Why my code crashes
    By ICool in forum C Programming
    Replies: 19
    Last Post: 09-08-2007, 09:03 AM
  4. Problem w/ console application compadibility
    By DarkMortar in forum C Programming
    Replies: 2
    Last Post: 05-16-2006, 07:13 PM
  5. making a stealthy win32 console application?
    By killdragon in forum C++ Programming
    Replies: 3
    Last Post: 09-08-2004, 02:50 PM

Tags for this Thread