Bitcoin Forum
October 23, 2018, 09:48:19 PM *
News: Make sure you are not using versions of Bitcoin Core other than 0.17.0 [Torrent], 0.16.3, 0.15.2, or 0.14.3. More info.
 
   Home   Help Search Donate Login Register  
Pages: [1]
  Print  
Author Topic: Help Needed (Fixed): Open Transactions (Windows API)  (Read 1884 times)
da2ce7
Legendary
*
Offline Offline

Activity: 1221
Merit: 1000


Live and Let Live


View Profile
August 28, 2012, 07:08:32 AM
 #1

Hello, I'm the main windows developer for Open Transactions:
(don't know about Open Transactions check out my other thread: https://bitcointalk.org/index.php?topic=77301.0)

I need the help of a Windows API .NET CLI/C++ expert.

I have been trying to develop a CLI/C++ interface for the OTAPI (Open Transactions API).  To allow any .NET developer easy access in calling OT functions.  (Without needing P/Invoke and Swig).

I have got all the code compiling, without warnings.  I'm properly doing the __declspec(dllexport) and __declspec(dllimport) (afaict).

However on execution, I'm getting the impossible to debug:

(x64):

Quote
An unhandled exception of type 'System.AccessViolationException' occurred in ot_clr_prompt.exe

Additional information: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.


(x86):

Quote
A first chance exception of type 'System.BadImageFormatException' occurred in ot_clr_prompt.exe

Additional information: Could not load file or assembly 'otapicli.dll' or one of its dependencies.  is not a valid Win32 application. (Exception from HRESULT: 0x800700C1)

Need a Windows API Expert to help me with a CLI/C++ interface error.


When debugging the suspect code its:

Code: (mcrtexe.cpp)
#if defined (_MANAGED_MAIN)
            mainret = main(arguments);   <-  the exception happens here.
#else  /* defined (_MANAGED_MAIN) */

However I'm finding it impossible to debug further.
I'm compiling all the source code with the same mode: Multi-threaded Debug DLL (/MDd) <- I even compile my own versions of ChaiScript, protobuf, and ZMQ, so be certain that they are using the same compiler settings.


All of the DLL's seem to be linked properly, and I have been quite careful about the references.

If anyone (maybe expert), wants to delve into this rabbit hole with me, and help, please checkout: https://github.com/da2ce7/Open-Transactions

I have full install setup instructions here: https://github.com/da2ce7/Open-Transactions/blob/master/docs/INSTALL-Windows.txt

In #opentransactions on freenode, I am regularly on-line as 'da2ce7.'


I think that this features, if possible to get stable, will be a big boon for writing a OT GUI for windows.

The suspect code files are:

https://github.com/da2ce7/Open-Transactions/blob/master/project/ot_clr_prompt/ot_clr_prompt.cpp  <- my test CLI file

https://github.com/da2ce7/Open-Transactions/blob/master/include/otapi/otapicli.h <- the CLI/C++ interface;
https://github.com/da2ce7/Open-Transactions/blob/master/src/otapi/otapicli.cpp   <- the related cpp file.

https://github.com/da2ce7/Open-Transactions/blob/master/include/otapi/OTAPI_Wrapper.h <- the native C++ interface.

However I suppose this bug isn't so-much related to the code itself, but rather the build system.

I'll even chip a few Bitcoins in the way of anyone who can help me solve this issue.  Grin  Grin


Ok I have worked out the error.
I had a few things compiling as static libraries; while fine if your code is perfect; they hide many linker errors.   I changed of the projects in the solution to compile as DLLs, and cleaned up all the linker errors, (and warnings).  Bang-Presto.  It 'just worked' Smiley

One off NP-Hard.
Advertised sites are not endorsed by the Bitcoin Forum. They may be unsafe, untrustworthy, or illegal in your jurisdiction. Advertise here.
1540331299
Hero Member
*
Offline Offline

Posts: 1540331299

View Profile Personal Message (Offline)

Ignore
1540331299
Reply with quote  #2

1540331299
Report to moderator
1540331299
Hero Member
*
Offline Offline

Posts: 1540331299

View Profile Personal Message (Offline)

Ignore
1540331299
Reply with quote  #2

1540331299
Report to moderator
CIYAM
Legendary
*
Offline Offline

Activity: 1876
Merit: 1000


Ian Knowles - CIYAM Lead Developer


View Profile WWW
August 28, 2012, 07:34:39 AM
 #2

You did compile (everything?) using the /clr option?

With CIYAM anyone can create 100% generated C++ web applications in literally minutes.

GPG Public Key | 1ciyam3htJit1feGa26p2wQ4aw6KFTejU
da2ce7
Legendary
*
Offline Offline

Activity: 1221
Merit: 1000


Live and Let Live


View Profile
August 28, 2012, 08:58:36 AM
 #3

You did compile (everything?) using the /clr option?


Well depending what I was compiling, the pure native parts I was compiling with no /clr  (eg. otlib.dll, otapi.dll)

The Native/Managed interface, I compiled with: /clr (eg. otapicli.dll)

The Pure Managed test-app I compiled with /clr:pure (eg. ot_clr_prompt.exe)

The problem as far as I can tell is when linking the native dll's at runtime.  However debugging this is very difficult.

One off NP-Hard.
CIYAM
Legendary
*
Offline Offline

Activity: 1876
Merit: 1000


Ian Knowles - CIYAM Lead Developer


View Profile WWW
August 28, 2012, 09:09:18 AM
 #4

Well depending what I was compiling, the pure native parts I was compiling with no /clr  (eg. otlib.dll, otapi.dll)

The Native/Managed interface, I compiled with: /clr (eg. otapicli.dll)

The Pure Managed test-app I compiled with /clr:pure (eg. ot_clr_prompt.exe)

The problem as far as I can tell is when linking the native dll's at runtime.  However debugging this is very difficult.

It has been quite a while since I worked with this stuff but from memory it might be required to compile everything with at least /clr (unless using some special ugly syntax perhaps) so maybe try compiling the oltlib.dll and otapi.dll with it just to see what happens.

Also perhaps this might be of some help: http://msdn.microsoft.com/en-us/library/ms235282.aspx

With CIYAM anyone can create 100% generated C++ web applications in literally minutes.

GPG Public Key | 1ciyam3htJit1feGa26p2wQ4aw6KFTejU
da2ce7
Legendary
*
Offline Offline

Activity: 1221
Merit: 1000


Live and Let Live


View Profile
August 28, 2012, 01:57:33 PM
 #5

It has been quite a while since I worked with this stuff but from memory it might be required to compile everything with at least /clr (unless using some special ugly syntax perhaps) so maybe try compiling the oltlib.dll and otapi.dll with it just to see what happens.

Also perhaps this might be of some help: http://msdn.microsoft.com/en-us/library/ms235282.aspx


So I have created a test-case, this is just 2 DLL files and a Managed exe file:

https://github.com/da2ce7/MessagePass

It works fine, so it at-least shows that I was on the right idea originally;

Yet, I am no closer to knowing why it crashes for OT.

One off NP-Hard.
da2ce7
Legendary
*
Offline Offline

Activity: 1221
Merit: 1000


Live and Let Live


View Profile
August 28, 2012, 06:41:09 PM
 #6

Ok I have worked out the error.
I had a few things compiling as static libraries; while fine if your code is perfect; they hide many linker errors.   I changed of the projects in the solution to compile as DLLs, and cleaned up all the linker errors, (and warnings).  Bang-Presto.  It 'just worked'

One off NP-Hard.
CIYAM
Legendary
*
Offline Offline

Activity: 1876
Merit: 1000


Ian Knowles - CIYAM Lead Developer


View Profile WWW
August 29, 2012, 05:12:40 AM
 #7

Ok I have worked out the error.
I had a few things compiling as static libraries; while fine if your code is perfect; they hide many linker errors.   I changed of the projects in the solution to compile as DLLs, and cleaned up all the linker errors, (and warnings).  Bang-Presto.  It 'just worked'

Glad you worked it out - provided that the data and functions in any static libraries are only used by the native DLL's then it should "just work".

The problem is that you probably need to define DLL function wrappers to expose anything in those static libraries that is needed by the managed interface (so you can still keep static libraries but just need to be careful with their usage).

With CIYAM anyone can create 100% generated C++ web applications in literally minutes.

GPG Public Key | 1ciyam3htJit1feGa26p2wQ4aw6KFTejU
Pages: [1]
  Print  
 
Jump to:  

Sponsored by , a Bitcoin-accepting VPN.
Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!