473,471 Members | 1,696 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Problem with calling unmanaged function from VC++

I'm very new to Windows development, all
of my background is in Linux, so please bear with me. I am working
on a class project and just for fun I'm building a frontend using
VC++ 2003. The project uses the OpenSSL crypto libraries
(specifically the BIGNUM functions). The offending code is:
if (this->rbtnSetKeysize->Checked) {
this->intKeysize = 512;
// Load the Prime Number and calculate the Secret Value
this->statusBar1->Text = "Generating Prime and Secret
values...";
this->bnPrime = BN_generate_prime(NULL,
this->intKeysize, 1, NULL, NULL, NULL, NULL);
this->bnTmp = BN_generate_prime(NULL, this->intKeysize,
1, NULL, NULL, NULL, NULL);
BN_mod(this->bnSecret, this->bnTmp, this->bnPrime,
this->bnctxContext);
this->statusBar1->Text = "Prime and Secret values
generated.";
} else {
this->statusBar1->Text = "Loading Prime Number from
File...";

FileStream *fs = new
FileStream(this->txtInputFile->Text,
FileMode::Open, FileAccess::Read,
FileShare::None);
StreamReader *sr = new StreamReader(fs);
BN_hex2bn(&bnPrime, sr->ReadLine());
fs->Close();

this->intKeysize = BN_num_bits(this->bnPrime);
this->statusBar1->Text = "Generating Secret
Value...";
this->bnTmp = BN_generate_prime(NULL, this->intKeysize,
1, NULL, NULL, NULL, NULL);
BN_mod(this->bnSecret, this->bnTmp, this->bnPrime,
this->bnctxContext);
this->statusBar1->Text = "Secret Value
Generated";
} // End If
I am trying to call the BN_hex2bn function, which takes the address of
a dynamic BIGNUM as a parameter. I have bnPrime declared as a BIGNUM
* variable. However, when the call to the function in the snippet
below goes through the compiler, I get the following error:

error C2664: 'BN_hex2bn': cannot convert parameter 1 from 'BIGNUM
*__gc *' to 'BIGNUM **'

Any ideas? I'm having other problems as well, but I figured I
wouldn't hit you all at once. Thanks for your help.

Alex

Nov 17 '05 #1
2 1587
TOM
In VC++ .NET the __gc type is garbage collected. This means that the
run-time is free to move it around in memory anytime
it wants. Thus, you cannot pass a pointer that could be moved into a
non-managed routine. You need to pin the pointer
(locking it's memory location) before passing it to a non-managed function.
The compiler is trying to help you avoid
this problem by making it impossible to cast the pointer. Once you pin it,
you can cast it any way you need (that
makes sense).

void __pin * newptr = bnPrime;

Once newptr goes out of scope (or is set to zero), the __gc object gets
unpinned from memory.

Check out the help for __pin and other .NET isms (__box, etc.).

-- Tom

"darkhonor" <al**@darkhonor-dot-com.no-spam.invalid> wrote in message
news:40**********@127.0.0.1...
I'm very new to Windows development, all
of my background is in Linux, so please bear with me. I am working
on a class project and just for fun I'm building a frontend using
VC++ 2003. The project uses the OpenSSL crypto libraries
(specifically the BIGNUM functions). The offending code is:
if (this->rbtnSetKeysize->Checked) {
this->intKeysize = 512;
// Load the Prime Number and calculate the Secret Value
this->statusBar1->Text = "Generating Prime and Secret
values...";
this->bnPrime = BN_generate_prime(NULL,
this->intKeysize, 1, NULL, NULL, NULL, NULL);
this->bnTmp = BN_generate_prime(NULL, this->intKeysize,
1, NULL, NULL, NULL, NULL);
BN_mod(this->bnSecret, this->bnTmp, this->bnPrime,
this->bnctxContext);
this->statusBar1->Text = "Prime and Secret values
generated.";
} else {
this->statusBar1->Text = "Loading Prime Number from
File...";

FileStream *fs = new
FileStream(this->txtInputFile->Text,
FileMode::Open, FileAccess::Read,
FileShare::None);
StreamReader *sr = new StreamReader(fs);
BN_hex2bn(&bnPrime, sr->ReadLine());
fs->Close();

this->intKeysize = BN_num_bits(this->bnPrime);
this->statusBar1->Text = "Generating Secret
Value...";
this->bnTmp = BN_generate_prime(NULL, this->intKeysize,
1, NULL, NULL, NULL, NULL);
BN_mod(this->bnSecret, this->bnTmp, this->bnPrime,
this->bnctxContext);
this->statusBar1->Text = "Secret Value
Generated";
} // End If
I am trying to call the BN_hex2bn function, which takes the address of
a dynamic BIGNUM as a parameter. I have bnPrime declared as a BIGNUM
* variable. However, when the call to the function in the snippet
below goes through the compiler, I get the following error:

error C2664: 'BN_hex2bn': cannot convert parameter 1 from 'BIGNUM
*__gc *' to 'BIGNUM **'

Any ideas? I'm having other problems as well, but I figured I
wouldn't hit you all at once. Thanks for your help.

Alex

Nov 17 '05 #2
Rao
Can you please tell us which type of project did you select (in VC++
2003). Do you intend to target your application to .Net Framework?
Please elaborate.

Regards,
--Rao TRN
Nov 17 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: AHN | last post by:
Hi, folks; Please instruct a newbie in a very regular matter. How'm I calling an unmanaged dll written in vb from unmanaged vc++? Same question for (mainframe) c++? Thank you very much.
4
by: | last post by:
I am stuck in a situation and I do believe that this should work, but it doesn't. I have a unmanaged dll, that uses MFC. This works great. Now I recompile the unmanaged dll so it contains...
7
by: Kristof Thys via .NET 247 | last post by:
Post a new message to microsoft.public.dotnet.languages.vc http://www.dotnet247.com/247reference/default.aspx Hello, I've been struggling for weeks with this problem, I hope I find some...
17
by: Bill Grigg | last post by:
I have been successfully calling DLL's using VC++ 6.0 and also using VC++7.1 (.NET). I only mention this because I have never felt comfortable with the process, but nonetheless it did work....
8
by: Nadav | last post by:
Hi, Introduction: ********************* I am writing a mixed mode application I have a COM module and a .NET module that communicate with each other. The COM exposes a custom sink interface,...
6
by: guxu | last post by:
I have a managed C++ code which calls some methods in unmanaged C++ DLL. In my unmanaged DLL, I have a PROTECTED virutal function in a base class and derived class has a PRIVATE function which...
3
by: aaron.m.johnson | last post by:
Help me understand this, please. I have an older VC++ COM DLL that I'm using in a C# project. One of the COM objects takes a callback object as a parameter so that it can spin off a thread and...
3
by: Klaus | last post by:
Hi, I have an existing VC 6 MFC application which communicates asynchronly with a VC 2005 managed code dll. I use an unmanaged base class with virtual functions to access methods in the MFC...
8
by: Chizl | last post by:
I'm building a web server and having some issues with the TCPListener.Start(BackLog). It doesn't seem to do as expected. I'm using MS Web Stress Tool to test against my web server and when I...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.