Author

Topic: MS Visual C++ help (Read 950 times)

hero member
Activity: 765
Merit: 503
March 15, 2015, 11:28:37 PM
#3
Thanks ca333,

How come I can get the basic calculator to work, with just referencing the c++ project?
hero member
Activity: 521
Merit: 522
Developer - EthicHacker - BTC enthusiast
March 14, 2015, 11:25:03 AM
#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.)
hero member
Activity: 765
Merit: 503
March 13, 2015, 05: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.
Jump to: