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

import dll c++ function

Any body knows how to convert this DLL function to C# ?

DWORD WINAPI
importfunction(LPSTR lpBuffer, LPDWORD nSize);

Nov 17 '05 #1
5 7268
"centrino" <ce******@discussions.microsoft.com> wrote in message
news:45**********************************@microsof t.com...
Any body knows how to convert this DLL function to C# ?

DWORD WINAPI
importfunction(LPSTR lpBuffer, LPDWORD nSize);


[System.Runtime.InteropServices.DllImport(my.dll)]
static extern System.Int32
importfunction([System.Runtime.InteropServices.MarshalAs(System.Ru ntime.InteropServices.UnmanagedType.LPStr)]
string lpBuffer,
System.IntPtr nSize
);
If this is from a Win32 function you can probably find it at

http://pinvoke.net/

-- Alan
Nov 17 '05 #2

"centrino" <ce******@discussions.microsoft.com> wrote in message
news:45**********************************@microsof t.com...
Any body knows how to convert this DLL function to C# ?

DWORD WINAPI
importfunction(LPSTR lpBuffer, LPDWORD nSize);

[DllImport("your.dll", CallingConvention = CallingConvention.StdCall)]
static extern importfunction
(
[MarshalAs(UnmanagedType.LPTStr)]
string lpBuffer,
ref int nSize
);

Willy.

Nov 17 '05 #3
I don't know why i still get a empty buffer :

there is a other similar function:

DWORD WINAPI importfunction(
LPWSTR lpBuffer,
LPDWORD nSize
);
[DllImport("mydll", SetLastError=true)]
private static extern uint importfunction(

[MarshalAs(UnmanagedType.LPWStr)]
StringBuilder pBuffer,
ref uint pBufferSize
);

"Willy Denoyette [MVP]" wrote:

"centrino" <ce******@discussions.microsoft.com> wrote in message
news:45**********************************@microsof t.com...
Any body knows how to convert this DLL function to C# ?

DWORD WINAPI
importfunction(LPSTR lpBuffer, LPDWORD nSize);

[DllImport("your.dll", CallingConvention = CallingConvention.StdCall)]
static extern importfunction
(
[MarshalAs(UnmanagedType.LPTStr)]
string lpBuffer,
ref int nSize
);

Willy.

Nov 17 '05 #4

"centrino" <ce******@discussions.microsoft.com> wrote in message
news:04**********************************@microsof t.com...
I don't know why i still get a empty buffer :

there is a other similar function:

DWORD WINAPI importfunction(
LPWSTR lpBuffer,
LPDWORD nSize
);
[DllImport("mydll", SetLastError=true)]
private static extern uint importfunction(

[MarshalAs(UnmanagedType.LPWStr)]
StringBuilder pBuffer,
ref uint pBufferSize
);

"Willy Denoyette [MVP]" wrote:


Sorry but this is not the signature I've posted, WINAPI means stdcall
calling convention, why did you change it.
Also changed is the string argument, now it is a LPWSTR, why the change?

Did you allocate a StringBuilder big enough to hold the returned string?
What is there returned as nSize?
The problem with PInvoke is that you really need the description of the
function, else you have to guess things like:
- LPWSTR is what a fixed size buffer or not, who allocates the buffer?
- nSize is what the size of the buffer returned or the size requested?

Willy.

Nov 17 '05 #5

"centrino" <ce******@discussions.microsoft.com> wrote in message
news:B7**********************************@microsof t.com...
Hi Willy,

Thanks for your post !

I get the the size of the buffer returned nSize, but i "see" notthing in
StringBuffer lpBuffer.
StringBuilder lpBuffer = new StringBuilder(256);

The function return ERROR_SUCCESS=0 and NDIS_ERROR_SUCCESS=0. It seems
correct !?

i dont know why ! I tryed to get buffer with byte[], but i get notthing.

regards


What's the Length of the SB reurned?
Did yoy try lpBuffer.ToString()?
Are you sure the buffer contains a UNICODE string?
What function are you calling exactly?

Willy.
Nov 17 '05 #6

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

Similar topics

7
by: David Poundall | last post by:
importedfiles = {} for f in FileList f2 = f.split('.') # strip the .py, .pyc __import__(f2) s2 = f2+'.main()' # main is the top file in each import c = compile(s2, '', 'eval')...
3
by: Anthony Robinson | last post by:
I have an issue I've been working on that has proven to be quite troublesome. I already have an idea of what the anwser may be, but would like to solicit some suggestions or other ideas from you...
4
by: ofmars | last post by:
Hi there, In C# I'm using a DLL import attribute to call a function from this DLL. This function was written in an older version of Vb and I know the name of this function and it should...
19
by: Riko Wichmann | last post by:
hi everyone, I'm googeling since some time, but can't find an answer - maybe because the answer is 'No!'. Can I call a function in python inline, so that the python byte compiler does...
0
by: kagorami | last post by:
Q: How do you return a LPSTR from unmanaged code? A: Use a StringBuilder. What about this: public struct CSTRUCT { string return_value; } How do you get a LPSTR from unmanaged code when it...
2
by: groves | last post by:
Can anybody give me an example of how to import a function of module X in module y. And please if yu can use classes(Object oriented approach) would be great. The problem is that I have created...
1
by: Child of His | last post by:
I have been through every trick I know, or has been suggested. I have a one to two million line fixed field database in text format. I want to bring it into Access 97. When I use the external...
3
by: MichalSody | last post by:
How cann I import & use these function from an old C++ dll ? Only this, I've got are these two signatures of function I wannt use in my C# app. DllExport int DLLAPI drawImage( char...
5
by: ManWithNoName | last post by:
Hi! I'm somewhat new to python (using 2.5 on w2k) Currently I am trying to organize a structure for a project, and import all necessary files and so on. Everything went fine until I tried...
3
by: Kurda Yon | last post by:
Hi, I would like to import a function from a file which is located not in the same directory as the main program (from which the function needed to be imported). Could anybody pleas tell me...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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...

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.