473,386 Members | 1,738 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,386 software developers and data experts.

Interaction woth a c DLL

I have to pass a structure with some strings and a few
arrays to a dll written in c from my VB.NET code. Any
information on how to go about doing it. Any website
addresses where related information can be found will also
be of great help.

Thanks
Nov 20 '05 #1
3 1254
"baboo" <ba***@discussions.microsoft.com> schrieb
I have to pass a structure with some strings and a few
arrays to a dll written in c from my VB.NET code. Any
information on how to go about doing it. Any website
addresses where related information can be found will also
be of great help.


If you've got VB/VS.NET:

<F1>
VS.NET
.NET Framework
Programming with .NET Framework
Interoperating with unmanaged code

especially these sub topics:

Consuming unmanged DLL functions
Design Considerations For Interoperation
Interop Marshalling
If you only have the SDK: http://msdn.microsoft.com
--
Armin

http://learn.to/quote
http://www.plig.net/nnq/nquote.html

Nov 20 '05 #2
Thanks for the info... i looked at that information but
there is not much that will help me solve my problem which
is:

I have to pass an array of strings inside a structure,
from .NET code to a 'C' DLL, though i am able to pass the
structure.. the c code gives me garbage values for that
array.
the .NET code is:

<StructLayout(LayoutKind.Sequential, CharSet:=CharSet.Ansi)
Public Structure Test Dim ErrorValue As Double
Dim FieldNumber As Integer
Dim Dummy As Integer
Public ControlNames() As String
End Structure

The "ControlNames" array is an array of 15 strings with
each string being 50 characters long.

and the 'C' structure which takes the values is:

struct Test { double ErrorValue;
int FieldNumber;
int Dummy;
char sFixUpCtrl[15][50];
};

while debugging i find that the values for
the "ControlNames" array in 'C' are garbage.

any idea about how to go about fixing this problem??

~.~.~.~.~.~.
Baboo
-----Original Message-----
"baboo" <ba***@discussions.microsoft.com> schrieb
I have to pass a structure with some strings and a few
arrays to a dll written in c from my VB.NET code. Any
information on how to go about doing it. Any website
addresses where related information can be found will also be of great help.


If you've got VB/VS.NET:

<F1>
VS.NET
.NET Framework
Programming with .NET Framework
Interoperating with unmanaged code

especially these sub topics:

Consuming unmanged DLL functions
Design Considerations For Interoperation
Interop Marshalling
If you only have the SDK: http://msdn.microsoft.com
--
Armin

http://learn.to/quote
http://www.plig.net/nnq/nquote.html

.

Nov 20 '05 #3
On 2003-11-10, baboo <ba***@discussions.microsoft.com> wrote:
Thanks for the info... i looked at that information but
there is not much that will help me solve my problem which
is:

I have to pass an array of strings inside a structure,
from .NET code to a 'C' DLL, though i am able to pass the
structure.. the c code gives me garbage values for that
array.
the .NET code is:

<StructLayout(LayoutKind.Sequential, CharSet:=CharSet.Ansi)
Public Structure Test

Dim ErrorValue As Double
Dim FieldNumber As Integer
Dim Dummy As Integer
Public ControlNames() As String
End Structure

The "ControlNames" array is an array of 15 strings with
each string being 50 characters long.

and the 'C' structure which takes the values is:

struct Test { double ErrorValue;
int FieldNumber;
int Dummy;
char sFixUpCtrl[15][50];
};


This one is a little problematic... Normally, a fixed length array or
string in side of a structure is not a problem... For example, if it
was a single 50 character string:

<StructLayout(LayoutKind.Sequential, CharSet:=CharSet.Ansi)> _
Public Structure Test
Public ErrorValue As Double
Public FieldNumber As Integer
Public Dummy As Integer

<MarshalAs(UnmanagedType.ByValTStr, SizeConst:=50)> _
Public sFixUpCtrl As String
End Structure

But your's is a fixed two dimensional array. I have never had that
come up before, and I really don't see a good way to do it with in the
bounds of what is currently defined in the framework...

As a work around (unless someone comes up with a better idea, or knows a
way to do this directly), I would suggest just passing a single string
buffer big enough to hold the entire thing, and then chunk the data on
the return. In theory that should work since arrays are just contiguos
blocks of memory - even if they are 2D. So maybe something like (you
may have to play with the numbers - I'm sort of sleepy right now :)

<StructLayout(LayoutKind.Sequential, CharSet:=CharSet.Ansi)> _
Public Structure Test
Public ErrorValue As Double
Public FieldNumber As Integer
Public Dummy As Integer

<MarshalAs(UnmanagedType.ByValTStr, SizeConst:=750)> _
Public sFixUpCtrl As String
End Structure

And then, just do something like:

'Call your api call
Dim st As Test
.....

' chunk the string
Dim s(14) As String

For i As Integer = 0 To 14
s(i) = st.sFixUpCtrl.SubString(i*50, 50)
Next i

Oi! I'm getting sleepy... I hope I'm not doing something stupid in the
above little loop. But anyway, it's an idea that may work. I'll see if
I can find any more info on this tomorrow...

--
Tom Shelton
MVP [Visual Basic]
Nov 20 '05 #4

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

Similar topics

1
by: Alex Cicco | last post by:
Hi, I am new to SQL. Please bear with me and allow me to ask a dumb question. I am debugging a stored procedure (written in Trans-SQL), and I found that the SQL analyzer that I use doesn't...
2
by: richard | last post by:
Hi, I am about to start developing an n-tier system. And was hoping to get an insight into the best ways of doing this. Inparticular, I want to know how I can develop classes/component to be...
3
by: Aaron Queenan | last post by:
I have a form which performs some asynchronous code. I want to display a wait cursor when it starts, and hide the wait cursor when it has completed. This part works fairly well, using: ...
2
by: deko | last post by:
When to use a privileged user thread rather than a windows service? That's the question raised in a previous post . It was suggested that if the service needs to interact with a WinForms app...
4
by: vivek | last post by:
I am new to flash and want someone to guide me, Is it possible to create a UI entirely in Flash and that will inetract with C# components (backend) and these components will in return interact...
2
by: Alberto | last post by:
How do you write the interaction diagram's messages in c#? like calling a method in the object class? like an event? Thank you
2
by: =?Utf-8?B?bXIgcGVhbnV0?= | last post by:
I want to activate an application (Excel) in code. If I reference microsoft.visualbasic, I could use: Interaction.AppActivate("Microsoft Excel"); But I wold rather use a native C# approach. I...
1
by: dwij2u | last post by:
Hi All, Can someone guide me on how we can modify the below script so that no user interaction is required to feed the password when the script is run, current scenario is like if I try to login...
0
by: Omar Abid | last post by:
Reason of this project: The Microsoft.VisualBasic.Interaction class exposes many useful commands and methods that were available in Visual Basic like AppActivate, Beep, Callbyname... This...
3
by: mmm | last post by:
I am looking for advice on Python Editors and IDEs I have read other posts and threads on the subject and my two questions at this time are mainly about the IDLE-like F5-run facilities. While I...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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...

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.