Help with crashlog analysis...

 
Hello,

I've been attempting to use a VB.NET library through a Managed C++ wrapper, and I'm having some issues. I could also use C#, but I'm assuming if it works for one, it will work for the other. I'm hoping that someone here can guide me. I read on the metaquotes.net forum that this was possible: http://www.metatrader4.com/forum/997/

1) IS it possible? - I'm assuming MT4 is unmanaged C++ code. It seems to be able to load the managed C++ wrapper OK, so logically I think it would work.

2) If it is possible, can someone help with the crashlog? I followed the instructions in 'How to Use Crashlogs to Debug Your Own DLLs', but the log I'm getting is obviously a bit more complicated due to the managed/unmanaged components.

Here is the log:

There has been a critical error
Time        : 2006.08.19 22:29
Program     : Client Terminal
Version     : 4.00 (build: 195, 31 Jul 2006)
Owner       : MetaQuotes Software Corp. (MetaTrader)
OS          : Windows XP Professional 5.1 Service Pack 2 (Build 2600)
Processors  : 2, type 586, level 15
Memory      : 2096620/1444100 kb
Exception   : E0434F4D
Address     : 7C812A5B
Access Type : NA
Access Addr : 00000000
 
Registers   : EAX=0321F8B8 CS=001b EIP=7C812A5B EFLGS=00000246
            : EBX=00000001 SS=0023 ESP=0321F8B4 EBP=0321F908
            : ECX=00196780 DS=0023 ESI=00000000 FS=003b
            : EDX=00000000 ES=0023 EDI=00000000 GS=0000
 
Stack Trace : 79238B7D 79238B00 79238AB4 79258705
            : 791D7746 02622F76 0045D617 0045051A
            : 00000000 00000000 00000000 00000000
            : 00000000 00000000 00000000 00000000
Modules     :
          1 : 00400000 00293000 E:Program FilesMT4Basicterminal.exe
          2 : 01050000 0000E000 E:Program FilesLogitechSetPointlgscroll.dll
          3 : 01340000 00010000 C:WINDOWSsystem32ctagent.dll
          4 : 018C0000 00015000 C:WINDOWSsystem32nvwddi.dll
          5 : 02080000 00006000 E:Program FilesMT4BasicexpertslibrariesCSharpSample.dll
          6 : 02190000 0000F000 C:WINDOWSsystem32ZoneLabsvetredir.dll
          7 : 02390000 00015000 C:WINDOWSsystem32ZoneLabsisafeif.dll
          8 : 10000000 0016F000 C:WINDOWSsystem32nview.dll
          9 : 10D00000 0000D000 E:Program FilesLogitechSetPointGameHook.dll
         10 : 20000000 002C5000 C:WINDOWSsystem32xpsp2res.dll
         11 : 22000000 00007000 C:PROGRA~1ZONELA~1ZONEAL~1MAILFR~1mlfhook.dll
         12 : 51A70000 00080000 C:WINDOWSMicrosoft.NETFrameworkv1.1.4322diasymreader.dll
         13 : 5AD70000 00038000 C:WINDOWSsystem32UxTheme.dll
         14 : 605D0000 00009000 C:WINDOWSsystem32mslbui.dll
         15 : 662B0000 00058000 C:WINDOWSsystem32hnetcfg.dll
         16 : 71A50000 0003F000 C:WINDOWSsystem32mswsock.dll
         17 : 71A90000 00008000 C:WINDOWSSystem32wshtcpip.dll
         18 : 71AA0000 00008000 C:WINDOWSsystem32WS2HELP.dll
         19 : 71AB0000 00017000 C:WINDOWSsystem32WS2_32.dll
         20 : 71BF0000 00013000 C:WINDOWSsystem32SAMLIB.dll
         21 : 72D10000 00008000 C:WINDOWSsystem32msacm32.drv
         22 : 72D20000 00009000 C:WINDOWSsystem32wdmaud.drv
         23 : 73DD0000 000FE000 C:WINDOWSsystem32MFC42.DLL
         24 : 74720000 0004B000 C:WINDOWSsystem32MSCTF.dll
         25 : 76380000 00005000 C:WINDOWSsystem32MSIMG32.dll
         26 : 763B0000 00049000 C:WINDOWSsystem32comdlg32.dll
         27 : 769C0000 000B3000 C:WINDOWSsystem32USERENV.dll
         28 : 76B40000 0002D000 C:WINDOWSsystem32WINMM.dll
         29 : 76BF0000 0000B000 C:WINDOWSsystem32PSAPI.DLL
         30 : 76C30000 0002E000 C:WINDOWSsystem32WINTRUST.dll
         31 : 76C90000 00028000 C:WINDOWSsystem32IMAGEHLP.dll
         32 : 76F20000 00027000 C:WINDOWSsystem32DNSAPI.dll
         33 : 76F60000 0002C000 C:WINDOWSsystem32WLDAP32.dll
         34 : 76FB0000 00008000 C:WINDOWSSystem32winrnr.dll
         35 : 76FC0000 00006000 C:WINDOWSsystem32rasadhlp.dll
         36 : 77120000 0008C000 C:WINDOWSsystem32OLEAUT32.dll
         37 : 773D0000 00102000 C:WINDOWSWinSxSX86_Microsoft.Windows.Common-Controls_6595b64144ccf1df_6.0.2600.2180_x-ww_a84f1ff9COMCTL32.dll
         38 : 774E0000 0013D000 C:WINDOWSsystem32ole32.dll
         39 : 77690000 00021000 C:WINDOWSsystem32NTMARTA.DLL
         40 : 77A80000 00094000 C:WINDOWSsystem32CRYPT32.dll
         41 : 77B20000 00012000 C:WINDOWSsystem32MSASN1.dll
         42 : 77BD0000 00007000 C:WINDOWSsystem32midimap.dll
         43 : 77BE0000 00015000 C:WINDOWSsystem32MSACM32.dll
         44 : 77C00000 00008000 C:WINDOWSsystem32VERSION.dll
         45 : 77C10000 00058000 C:WINDOWSsystem32msvcrt.dll
         46 : 77D40000 00090000 C:WINDOWSsystem32USER32.dll
         47 : 77DD0000 0009B000 C:WINDOWSsystem32ADVAPI32.dll
         48 : 77E70000 00091000 C:WINDOWSsystem32RPCRT4.dll
         49 : 77F10000 00047000 C:WINDOWSsystem32GDI32.dll
         50 : 77F60000 00076000 C:WINDOWSsystem32SHLWAPI.dll
         51 : 79040000 00045000 C:WINDOWSMicrosoft.NETFrameworkv1.1.4322fusion.dll
         52 : 79170000 00026000 C:WINDOWSsystem32mscoree.dll
         53 : 791B0000 00266000 C:WINDOWSMicrosoft.NETFrameworkv1.1.4322mscorwks.dll
         54 : 79430000 0004D000 C:WINDOWSMicrosoft.NETFrameworkv1.1.4322MSCORJIT.DLL
         55 : 79780000 0020C000 c:windowsmicrosoft.netframeworkv1.1.4322mscorlib.dll
         56 : 79990000 0033C000 c:windowsassemblynativeimages1_v1.1.4322mscorlib1.0.5000.0__b77a5c561934e089_63d00461mscorlib.dll
         57 : 7C340000 00056000 C:WINDOWSsystem32MSVCR71.dll
         58 : 7C3A0000 0007B000 C:WINDOWSsystem32MSVCP71.dll
         59 : 7C800000 000F4000 C:WINDOWSsystem32kernel32.dll
         60 : 7C900000 000B0000 C:WINDOWSsystem32ntdll.dll
         61 : 7C9C0000 00815000 C:WINDOWSsystem32SHELL32.dll
 
Call stack  :
7C812A09:0052 [7C812A5B] RaiseException                   [C:WINDOWSsystem32kernel32.dll]
791D9CDB:5EEA2 [79238B7D] LogHelp_TerminateOnAssert        [C:WINDOWSMicrosoft.NETFrameworkv1.1.4322mscorwks.dll]
791D9CDB:5EE25 [79238B00] LogHelp_TerminateOnAssert        [C:WINDOWSMicrosoft.NETFrameworkv1.1.4322mscorwks.dll]
791D9CDB:5EDD9 [79238AB4] LogHelp_TerminateOnAssert        [C:WINDOWSMicrosoft.NETFrameworkv1.1.4322mscorwks.dll]
792425B4:16151 [79258705] GetCompileInfo                   [C:WINDOWSMicrosoft.NETFrameworkv1.1.4322mscorwks.dll]
791D4B25:2C21 [791D7746] ClrCreateManagedInstance         [C:WINDOWSMicrosoft.NETFrameworkv1.1.4322mscorwks.dll]
00459AB0:3B67 [0045D617] ?ExecuteStaticAsm@CExpertInterior
00450380:019A [0045051A] ?InitFunctionInt@CExpertInterior

Here is my managed C++ wrapper (it is set to "used managed extensions", and is compiled with /clr, etc.)

// This is the main DLL file.
 
#define WIN32_LEAN_AND_MEAN  // Exclude rarely-used stuff from Windows headers
#include <windows.h>
#include <stdlib.h>
#include <stdio.h>
//----
 
#pragma once
 
//#include "stdafx.h"
//#include "CSharpSample.h"
 
#using "MT4VBLib.dll"
 
using namespace System;

 
#define MT4_EXPFUNC __declspec(dllexport)
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
 
//----
struct MqlStr
  {
   int               len;
   char             *string;
  };
static int CompareMqlStr(const void *left,const void *right);
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
BOOL APIENTRY DllMain(HANDLE hModule,DWORD ul_reason_for_call,LPVOID lpReserved)
  {
//----
   switch(ul_reason_for_call)
     {
      case DLL_PROCESS_ATTACH:
      case DLL_THREAD_ATTACH:
      case DLL_THREAD_DETACH:
      case DLL_PROCESS_DETACH:
         break;
     }
//----
   return(TRUE);
  }
 
MT4_EXPFUNC int __stdcall GetIntValue(const int ipar)
  {
      int foo = ipar*2;
   return(foo);
  }
 
MT4_EXPFUNC int __stdcall MyFunction(const int ipar)
  {
      int foo = ipar*4;
   return(foo);
  }
 
 
MT4_EXPFUNC int __stdcall MultBy2(const int ipar)
  {
      int foo;
      MT4VBLib::MT4VBLib* pInteract = new MT4VBLib::MT4VBLib;
      foo = pInteract->VBMultBy2(ipar);
   return(foo);
  }


and here is the vb file

Public Class MT4VBLib
 
    Public Function VBGetIntValue(ByVal ipar As Integer) As Integer
        Return (ipar)
    End Function
 
    Public Function VBMultBy2(ByVal ipar As Integer) As Integer
        Dim foo As Integer
        foo = ipar * 2
        Return (foo)
    End Function
  
End Class

As you can see - everything is extremely simple - nothing fancy. Just trying to validate the "flow" of this setup to get started.

Loading the managed C++ wrapper works fine. If I only use functions that are directly defined in that wrapper, it all works - so clearly MT4 CAN actually use a managed component. The problem comes when I try to use the function from the VB.NET dll.

I've verified that all of this stuff works outside of MT4 by using a simple console test app. Works great there... Please help! Your response is greatly appreciated.

Just for completeness, here is the test app that it works with:

// TestConsole.cpp : Defines the entry point for the console application.
//
 
#include "stdafx.h"
#using <mscorlib.dll>
#using "CSharpSample.dll"
using namespace System::Runtime::InteropServices;
using namespace System;
[DllImport("CSharpSample.dll")]
extern "C" int _stdcall GetIntValue  (int ipar);
 
[DllImport("CSharpSample.dll")]
extern "C" int _stdcall MyFunction  (int ipar);
 
[DllImport("CSharpSample.dll")]
extern "C" int _stdcall MultBy2       (int ipar);
 
int _tmain(int argc, _TCHAR* argv[])
{
    printf("Foo! n");
    int foo,foo1;
    foo = GetIntValue(8);
    printf("%dn",foo);    
    foo1 = MultBy2(15);
    printf("%dn",foo1);
    return 0;
}
 
I doubt about your function declarations.

See declarations of WinAPI functions and write like they
 
Hi stringo,

Thanks for your help - do you mean in VB? I'm a bit confused as to your specific meaning... Or, do you mean in the managed wrapper? Meaning

MT4_EXPFUNC int __stdcall MultBy2(const int ipar)
  {
      int foo;
      MT4VBLib::MT4VBLib* pInteract = new MT4VBLib::MT4VBLib;
      foo = pInteract->VBMultBy2(ipar);
   return(foo);
  }

is wrong?

I'm confused, because the WinAPI functions are of course unmanaged functions... Can you elaborate? See declarations of WinAPI functions in what kind of file? C++, C#, VB?


Thanks again,
CS
 

Yes, wrapper. Your sample looks right.

You cannot write in VB well formed (for MQL4) function

See declarations in C++

 

Great !!!

SS Solutions deployed ability to execute .Net(C#) code from mql script

with data exchange gateway http://www.mttrade.net

simple and robust solution