Bitcoin Forum
May 08, 2024, 12:56:32 PM *
News: Latest Bitcoin Core release: 27.0 [Torrent]
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: MS Visual C++ help  (Read 923 times)
doof (OP)
Hero Member
*****
Offline Offline

Activity: 765
Merit: 503


View Profile WWW
March 13, 2015, 10:26:43 AM
 #1

Hi people,

I've bought a USB Hardware RNG https://www.tindie.com/products/ubldit/truerng-hardware-random-number-generator/

There is some c++ code http://ubld.it/wp-content/uploads/2014/02/rng.h that Id like to use as a DLL in a C# project.  I've added the file and also a simple "calculator" code -> https://github.com/bitcoinbrisbane/truerng

This compiles, but I can't see the rng stuff, so it might just be an accessor problem, but it looks fine to me.  I thought Id post in the BTC forum because there are a lot of c++ and c# guys, and someone also might like to use the RNG too.

Happy to post over at stack over flow or something if its not suited here.
1715172992
Hero Member
*
Offline Offline

Posts: 1715172992

View Profile Personal Message (Offline)

Ignore
1715172992
Reply with quote  #2

1715172992
Report to moderator
1715172992
Hero Member
*
Offline Offline

Posts: 1715172992

View Profile Personal Message (Offline)

Ignore
1715172992
Reply with quote  #2

1715172992
Report to moderator
"The nature of Bitcoin is such that once version 0.1 was released, the core design was set in stone for the rest of its lifetime." -- Satoshi
Advertised sites are not endorsed by the Bitcoin Forum. They may be unsafe, untrustworthy, or illegal in your jurisdiction.
1715172992
Hero Member
*
Offline Offline

Posts: 1715172992

View Profile Personal Message (Offline)

Ignore
1715172992
Reply with quote  #2

1715172992
Report to moderator
ca333
Hero Member
*****
Offline Offline

Activity: 520
Merit: 522


Developer - EthicHacker - BTC enthusiast


View Profile
March 14, 2015, 04:25:03 PM
 #2

so you must IMPORT the dll in your c# program. and in your code its not binded.
see the code here will do it.

this is the DLLFUNCTIONS.cs which you after you make it compile it so it give you the output: DLLFUNCTIONS.DLL.
Code:
using System.Runtime.InteropServices; // InteropServices is for loading unmanaged code into c#
public class DLLFUNCTIONS {
  [DllImport("YOURDLL.Dll")] //DllImport imports the DLL so the entry point is known
  public static extern YOURFUNCTION1(YOURPARAMS); //provide the declarations for all your functions you want to use
  public static extern YOURFUNCTION2(YOURPARAMS);
}

what makes the above code?
so you import the DLL and then you declare your wrapper functions in the class (DLLFUNCTIONS). but because you have the c++ code with datatyps, structs, pointer arrays also for the texts, and so on and so on, so you must "translate" the .NET objects you use in your c# project for the c++ DLL so it understands this data. this is named "MARSHALING". it s a very complex technics with many features and i suggest you look into it and read it because its soo nice and gives soo mighty options.

ok when you have declared your DLLFUNCTIONS you compile it, and finally have a DLLFUNCTIONS.DLL now you can use it in ALL c# projects.

so then you use it with:
Code:
using DLLFUNCTIONS;

because now compiler know exactly where is entry point of DLL and also how translate the .NET objs to the correct types in the DLL with the parameters we have also declared in our wrapper functions.
 
when you need other help write me.
thank you.
ca333


(maybe mods put this in the technical support area. but i think rng project suits in this community. it s basic technology in BTC. so i think its also okay here with your project.)

this space is available (free) for humanitarian nonprofit organizations - please contact me
doof (OP)
Hero Member
*****
Offline Offline

Activity: 765
Merit: 503


View Profile WWW
March 16, 2015, 04:28:37 AM
 #3

Thanks ca333,

How come I can get the basic calculator to work, with just referencing the c++ project?
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!