473,395 Members | 1,856 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Need help, may be easy for you , I'm getting nuts.

Hi,

I have this DLL made with VB.NET made as a Class Library project. I
know this is managed code.

I have my other made with VC++.NET, unmanaged code.

The point is that I want to use function within my DLL in the VC++ project.

I've been reading document over the internet and this
http://msdn.microsoft.com/msdnmag/is...A/default.aspx

but I can't find a tutorial explaining how to integrate and use my
VB.NET DLL in VC++. There is text that says that I should import the
DLL content but it is not clear for me.

Does any of you would have a good reference to suggest to me?

I appreciate, thank you

Marty
Nov 17 '05 #1
3 1400
You have to write a mixed-mode DLL in C++ ( I don't think you can use
any other language, but I may be wrong here). I've done this before. The
mixed-mode DLL exports a pure C interface, and the C functions are
calling into the managed interface using Managed C++ (or C++/CLI once
VC++ 2005 is out).

extern "C"
{
__declspec(dllexport) bool __stdcall Convert([...])
// unmanaged function exported from the DLL
{
try
{
[...] just write your managed code here
return true;
}
catch(...)
{
}
return false;
}
}

You just have to solve the data marshalling, converting managed arrays
to unmanaged, and so on. It depends what you want to pass to the
function and what you want to return. For example, managed data can be
pinned and the pinned pointer passed to an unmanaged function:

MemoryStream __gc* managed_stream = new MemoryStream;
[...]
unsigned char managed_array __gc[] = managed_stream->GetBuffer();
unsigned char __pin* ptr = &managed_array[0];
unmanaged_callback(ptr, static_cast<unsigned>(managed_stream->Length));

You could be more specific if you have trouble with a certain detail.

Tom
Marty wrote:
Hi,

I have this DLL made with VB.NET made as a Class Library project. I
know this is managed code.

I have my other made with VC++.NET, unmanaged code.

The point is that I want to use function within my DLL in the VC++ project.

I've been reading document over the internet and this
http://msdn.microsoft.com/msdnmag/is...A/default.aspx

but I can't find a tutorial explaining how to integrate and use my
VB.NET DLL in VC++. There is text that says that I should import the
DLL content but it is not clear for me.

Does any of you would have a good reference to suggest to me?

I appreciate, thank you

Marty

Nov 17 '05 #2
Hi Tamas,

Thank you for your infromation.

It all start from there, I wanted to add a socket handler in my VC++
program, I've tried with this code that I got from the VC++ help file
(at end of email).

But I couldn't make it work, so I thaught to use the one I already made
in VB.NET, so I get to write my previous email.

What is better or easier? To integrate the code just below to my VC++
project?

Thanks for your help.

Marty

void main() {
try {
// Set the TcpListener on port 13000.
Int32 port = 13000;
IPAddress* localAddr = IPAddress::Parse(S"127.0.0.1");

// TcpListener* server = new TcpListener(port);
TcpListener* server = new TcpListener(localAddr, port);

// Start listening for client requests.
server->Start();

// Buffer for reading data
Byte bytes[] = new Byte[256];
String* data = 0;

// Enter the listening loop.
while (true) {
Console::Write(S"Waiting for a connection... ");

// Perform a blocking call to accept requests.
// You could also user server.AcceptSocket() here.
TcpClient* client = server->AcceptTcpClient();
Console::WriteLine(S"Connected!");

data = 0;

// Get a stream Object* for reading and writing
NetworkStream* stream = client->GetStream();

Int32 i;

// Loop to receive all the data sent by the client.
while (i = stream->Read(bytes, 0, bytes->Length)) {
// Translate data bytes to a ASCII String*.
data = Text::Encoding::ASCII->GetString(bytes, 0, i);
Console::WriteLine(String::Format(S"Received: {0}",
data));
// Process the data sent by the client.
data = data->ToUpper();

Byte msg[] = Text::Encoding::ASCII->GetBytes(data);

// Send back a response.
stream->Write(msg, 0, msg->Length);
Console::WriteLine(String::Format(S"Sent: {0}", data));
}

// Shutdown and end connection
client->Close();
}
} catch (SocketException* e) {
Console::WriteLine(S"SocketException: {0}", e);
}

Console::WriteLine(S"\nHit enter to continue...");
Console::Read();
}
Nov 17 '05 #3
ok, I finally find out to make it compile without erros, the first
bottleneck is passed.

Have a good day.

Marty

Marty wrote:
Hi Tamas,

Thank you for your infromation.

It all start from there, I wanted to add a socket handler in my VC++
program, I've tried with this code that I got from the VC++ help file
(at end of email).

But I couldn't make it work, so I thaught to use the one I already made
in VB.NET, so I get to write my previous email.

What is better or easier? To integrate the code just below to my VC++
project?

Thanks for your help.

Marty

void main() {
try {
// Set the TcpListener on port 13000.
Int32 port = 13000;
IPAddress* localAddr = IPAddress::Parse(S"127.0.0.1");

// TcpListener* server = new TcpListener(port);
TcpListener* server = new TcpListener(localAddr, port);

// Start listening for client requests.
server->Start();

// Buffer for reading data
Byte bytes[] = new Byte[256];
String* data = 0;

// Enter the listening loop.
while (true) {
Console::Write(S"Waiting for a connection... ");

// Perform a blocking call to accept requests.
// You could also user server.AcceptSocket() here.
TcpClient* client = server->AcceptTcpClient();
Console::WriteLine(S"Connected!");

data = 0;

// Get a stream Object* for reading and writing
NetworkStream* stream = client->GetStream();

Int32 i;

// Loop to receive all the data sent by the client.
while (i = stream->Read(bytes, 0, bytes->Length)) {
// Translate data bytes to a ASCII String*.
data = Text::Encoding::ASCII->GetString(bytes, 0, i);
Console::WriteLine(String::Format(S"Received: {0}",
data));
// Process the data sent by the client.
data = data->ToUpper();

Byte msg[] = Text::Encoding::ASCII->GetBytes(data);

// Send back a response.
stream->Write(msg, 0, msg->Length);
Console::WriteLine(String::Format(S"Sent: {0}", data));
}

// Shutdown and end connection
client->Close();
}
} catch (SocketException* e) {
Console::WriteLine(S"SocketException: {0}", e);
}

Console::WriteLine(S"\nHit enter to continue...");
Console::Read();
}

Nov 17 '05 #4

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

Similar topics

3
by: cazman | last post by:
Hi all, Let's say I have this: 1 2 fruit 154 4 5 fruit 178 1 2 vegetable 456 4 5 vegetable 458 1 2 nuts 123 4 5 nuts 485
1
by: Mike | last post by:
I have a web page that displays contact people in a drop down. the users selects a person then clicks the go button. The datagrid should pop with all the information on the select contact person,...
2
by: Lior | last post by:
Hi, I have an ASP.NET website that crashes under heavy load. I use a SQL Server DB. I get around 5500 hits per day. I keep getting the timeout expieried connection pool error. Sometimes it even...
6
by: Benjamin Walling | last post by:
We have 109 remote offices all running Sybase ASA Server. We collect data from these offices and consolidate it into our main server. I have written a program that will read from each office and...
21
by: Marina | last post by:
I've spent 2 months working on this Access 2003 db, get something done and then the 'boss' wants something different that what was originally stated, or wants to add this or that. It's been nuts,...
0
by: Billie Boy | last post by:
Hi to all. I’m new here and am coming to you from Melbourne Australia. So a big HELLO 2 ALL. Now I am encountering an annoying problem in the SQL builder of the copy of VB.6 that I am using at...
8
by: john | last post by:
To test a new piece of software designed to help with (among other things) eCommerce WWW site development. The software is fairly easy to use but you must fit a profile. Retail price is 120 GBP and...
20
by: mike | last post by:
I help manage a large web site, one that has over 600 html pages... It's a reference site for ham radio folks and as an example, one page indexes over 1.8 gb of on-line PDF documents. The site...
6
by: tims | last post by:
Hi, I'm working on an easy assignment only I can't get it working properly. All the program needs to do is accept the user-input value and display a message that many times. What I'm having trouble...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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...
0
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.