hi ,everyone ,please check my codes,i am really confused.
the codes of win32 dll is as follows:
***********************the win32 DLL writen in c++*****************
extern "C"
{
__declspec(dllexport) WCHAR* __stdcall getWNameOfComponnet();
}
WCHAR name[100];
BOOL APIENTRY DllMain( HMODULE hModule,
DWORD ul_reason_for_call,
LPVOID lpReserved
)
{
return TRUE;
}
WCHAR* getWNameOfComponnet(){
return name;
}
************************************************
*********************the win32 .def file************
EXPORT
getWNameOfComponnet @1
************************************************** ***
and I try to use the export in c#,but I can not get anything from
getprocaddress(,.)
**************import the prototype of api**
[DllImport ("kernel32.dll",EntryPoint="LoadLibraryW",
CharSet=CharSet.Unicode,CallingConvention=CallingC onvention.StdCall,
SetLastError =true)]
public extern static IntPtr LoadLibrary(String lpFileName);
[DllImport("Kernel32", EntryPoint = "GetProcAddress",
CharSet=CharSet.Unicode ,CallingConvention =
CallingConvention.StdCall,
SetLastError = true)]
public extern static IntPtr GetProcAddress(
IntPtr handle,
[MarshalAs(UnmanagedType.LPWStr)]string funcname);
**********************
**************get the export from my dll***
public delegate string getwname();
private static Delegate GetAddress(IntPtr dllModule, string
functionname, Type t)
{
IntPtr addr = GetProcAddress(dllModule, functionname);
//addr is always zero.why?
if (addr == IntPtr.Zero )
return null;
else
return Marshal.GetDelegateForFunctionPointer(addr, t);
}
public String callGetWname()
{
IntPtr huser32 =IntPtr.Zero ;
huser32 = LoadLibrary("my.dll");//the huser32 is ok,the
dll is loaded.
getwname mygetw = (getwname)GetAddress(huser32,
"getWNameOfComponnet",
typeof(getwname));
}
********************************
the getProcAddress(..) doesn't work.Where am i wrong? 8 4246
the getProcAddress(..) doesn't work.Where am i wrong?
Does the filename of the DLL you need to load change after compile time? If
not, let p/invoke handle all the dynamic loading mess for you and just use
DllImport and declare the function you need to call.
hi,Ben
the export of the DLL is right. I check them with a tool software.
and I change the prototype of getProcAddress(..) in C# as follows:
**************************
[DllImport("Kernel32.dll", EntryPoint = "GetProcAddress", CharSet =
CharSet.Ansi, CallingConvention = CallingConvention.StdCall , SetLastError =
true)]
public extern static IntPtr GetProcAddress(
IntPtr handle,
[MarshalAs(UnmanagedType.LPStr)]string funcname);
***************************
if I change it into unicode ,everything go wrong. I don't why ,maybe
GetProcAddress() only has ANSI version.
just put result here for someone may encounter the same problem.
"Ben Voigt [C++ MVP]" <rb*@nospam.nospamдÈëÏûÏ¢ÐÂÎÅ:eC**************@TK 2MSFTNGP06.phx.gbl...
>the getProcAddress(..) doesn't work.Where am i wrong?
Does the filename of the DLL you need to load change after compile time?
If not, let p/invoke handle all the dynamic loading mess for you and just
use DllImport and declare the function you need to call.
**************import the prototype of api**
[DllImport ("kernel32.dll",EntryPoint="LoadLibraryW",
CharSet=CharSet.Unicode,CallingConvention=CallingC onvention.StdCall,
SetLastError =true)]
public extern static IntPtr LoadLibrary(String lpFileName);
Just FYI, you shouldn't specify the LoadLibraryW entry point unless you
specified ExactSpelling = true on the DllImport attribute. You're already
specifying to use the Unicode character set, as such that would be handled
automatically. Also, you don't need to specify the EntryPoint unless it's
different than the name of the function you're defining. Just some nice
things you might want to do to help simplify your code. :o)
For example: This would need it.
[DllImport("myfile.dll", EntryPoint = "Foo")]
public static extern void Bar();
After looking in both the WinBase.h and Windows.h header files the MSDN
documentation states they're located in there was only a single declaration
for the GetProcAddress function - which leads me to believe you are correct
when you said that only the ANSI version is available. Not to mention there
is no information in the MSDN documentation indicating there is both a
Unicode and ANSI version available.
Perhaps because old C didn't allow Unicode characters in their definitions.
I don't know, I'm completely guessing there. Never used it before so I
couldn't say either way for sure. That's the only reason I could think of
why there wouldn't be a unicode version of the definition.
"Ryanivanka" <sa********@gmail.comwrote in message
news:%2****************@TK2MSFTNGP03.phx.gbl...
hi,Ben
the export of the DLL is right. I check them with a tool software.
and I change the prototype of getProcAddress(..) in C# as follows:
**************************
[DllImport("Kernel32.dll", EntryPoint = "GetProcAddress", CharSet =
CharSet.Ansi, CallingConvention = CallingConvention.StdCall , SetLastError
= true)]
public extern static IntPtr GetProcAddress(
IntPtr handle,
[MarshalAs(UnmanagedType.LPStr)]string funcname);
***************************
if I change it into unicode ,everything go wrong. I don't why ,maybe
GetProcAddress() only has ANSI version.
just put result here for someone may encounter the same problem.
"Ben Voigt [C++ MVP]" <rb*@nospam.nospam>
дÈëÏûÏ¢ÐÂÎÅ:eC**************@TK2MSFTNGP06.phx.gbl ...
>>the getProcAddress(..) doesn't work.Where am i wrong?
Does the filename of the DLL you need to load change after compile time? If not, let p/invoke handle all the dynamic loading mess for you and just use DllImport and declare the function you need to call.
On Jul 8, 6:34*pm, Ryanivanka <sarah.h...@gmail.comwrote:
the getProcAddress(..) doesn't work.Where am i wrong?
Here:
[DllImport("Kernel32", EntryPoint = "GetProcAddress",
CharSet=CharSet.Unicode ,CallingConvention =
CallingConvention.StdCall,
SetLastError = true)]
You either need to use CharSet=CharSet.Auto, or
EntryPoint="GetProcAddressW". If you specify CharSet explicitly, P/
Invoke won't auto-decorate the function name.
Ryanivanka wrote:
hi,Ben
the export of the DLL is right. I check them with a tool software.
Why are you using GetProcAddress? Use a DllImport attribute on *your*
function setting EntryPoint correctly and p/invoke will call LoadLibrary and
GetProcAddress for you.
>
and I change the prototype of getProcAddress(..) in C# as follows:
**************************
[DllImport("Kernel32.dll", EntryPoint = "GetProcAddress",
CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall ,
SetLastError = true)]
public extern static IntPtr GetProcAddress(
IntPtr handle,
[MarshalAs(UnmanagedType.LPStr)]string funcname);
***************************
if I change it into unicode ,everything go wrong. I don't why ,maybe
GetProcAddress() only has ANSI version.
just put result here for someone may encounter the same problem.
"Ben Voigt [C++ MVP]" <rb*@nospam.nospam>
дÈëÏûÏ¢ÐÂÎÅ:eC**************@TK2MSFTNGP06.phx.gbl ...
>>the getProcAddress(..) doesn't work.Where am i wrong?
Does the filename of the DLL you need to load change after compile time? If not, let p/invoke handle all the dynamic loading mess for you and just use DllImport and declare the function you need to call.
Thank you, Pavel.
It does work if I kick out the"CharSet" attribute.
-----------------------------------------
ÔÚ Wed, 9 Jul 2008 07:20:02 -0700 (PDT) £¬Pavel MinaevдµÀ£º
>On Jul 8, 6:34*pm, Ryanivanka <sarah.h...@gmail.comwrote:
>the getProcAddress(..) doesn't work.Where am i wrong?
Here:
>[DllImport("Kernel32", EntryPoint = "GetProcAddress", CharSet=CharSet.Unicode ,CallingConvention = CallingConvention.StdCall, SetLastError = true)]
You either need to use CharSet=CharSet.Auto, or EntryPoint="GetProcAddressW". If you specify CharSet explicitly, P/ Invoke won't auto-decorate the function name.
-----------------------------------------
Ö Àñ£¡
Ryanivanka sa********@gmail.com
hi,Ben.
what you ask remind me of another question.
I was told if I use LoadLibrary(..)to load a DLL, I have to freeLibrary(..) by myself too,because CLR won't do that for me? is this correct?
I use LoadLibrary(..) to control the bind of DLL by myself.And if I import my function using EntryPoint,would the DLL stay in the process's virtual address space until the process is ended?
-----------------------------------------
ÔÚ Wed, 9 Jul 2008 11:21:38 -0500 £¬Ben Voigt [C++ MVP]дµÀ£º
>Ryanivanka wrote:
>hi,Ben
the export of the DLL is right. I check them with a tool software.
Why are you using GetProcAddress? Use a DllImport attribute on *your* function setting EntryPoint correctly and p/invoke will call LoadLibrary and GetProcAddress for you.
>>
and I change the prototype of getProcAddress(..) in C# as follows: ************************** [DllImport("Kernel32.dll", EntryPoint = "GetProcAddress", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall , SetLastError = true)] public extern static IntPtr GetProcAddress( IntPtr handle, [MarshalAs(UnmanagedType.LPStr)]string funcname); ***************************
if I change it into unicode ,everything go wrong. I don't why ,maybe GetProcAddress() only has ANSI version.
just put result here for someone may encounter the same problem.
"Ben Voigt [C++ MVP]" <rb*@nospam.nospam> дÈëÏûÏ¢ÐÂÎÅ:eC**************@TK2MSFTNGP06.phx.gb l...
>>>the getProcAddress(..) doesn't work.Where am i wrong?
Does the filename of the DLL you need to load change after compile time? If not, let p/invoke handle all the dynamic loading mess for you and just use DllImport and declare the function you need to call.
-----------------------------------------
Ö Àñ£¡
Ryanivanka sa********@gmail.com
On Jul 10, 4:39*am, Ryanivanka <sarah.h...@gmail.comwrote:
I was told if I use LoadLibrary(..)to load a DLL, I have to freeLibrary(...) by myself too,because CLR won't do that for me? is this correct?
Yes. CLR garbage collector only collects memory, everything else is
"unmanaged resources", and you have to take care of it yourself.
I use LoadLibrary(..) to control the bind of DLL by myself.And if I import my function using EntryPoint,would the DLL stay in the process's virtual address space until the process is ended?
Yes. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Carl Waldbieser |
last post by:
I tried to adapt the instructions for building the M2Crypto module
(http://sandbox.rulemaker.net/ngps/m2/INSTALL.html) to build a version
compatible with Python2.3, but I've had some mixed results....
|
by: Jesper |
last post by:
Hi,
In visual studio 2003 I made an application that ran without problems on a
number of 50+ machines (all running .Net 1.1). Now I've recompiled the
program using Visual studio 2005, .Net 2.0...
|
by: Marcus Kwok |
last post by:
I am having a weird problem with my DataGrid that is bound to an
ArrayList. My situation is as follows:
I have two DataGrids on a modal form. The top grid populates an
ArrayList from a file,...
|
by: Budhi Saputra Prasetya |
last post by:
Hi,
I still have the same problem with embedding Windows Control. I'll just
requote what I posted last time:
I managed to create a Windows Form Control and put it on my ASP .NET page. I...
|
by: Michax |
last post by:
Hi,
I have problem with my py2exe. When I want to run my compiled exe, then
i get
error information like that:
Trackback (most recent call last):
File "mysql_gui.py", line 2 in ?
File...
|
by: Rene |
last post by:
Hello to all!
For a long time I have been "fighting" a problem compiling an OpenGL
program which uses GLUT. First I have put a question in a Watcom group
(I want to use this compiler) to which I...
|
by: pod |
last post by:
Hello
My OS is Windows2000
I am new to .NET
I developed a C# Windows Application that connects to a MS Access database on the network using proper UNC format.
It works perfectly on my...
|
by: Eddie |
last post by:
Hi
I am using lcc-win on Windows 98. I'm writing a simple c console app, and
I need to set the background color to blue. Here's the code I've got at
the moment:
_asm ( "movb $2, %ah\n"
"movb...
|
by: eliben |
last post by:
On Jun 27, 3:10 pm, eliben <eli...@gmail.comwrote:
Problem solved:
http://eli.thegreenplace.net/2008/06/28/compiling-python-extensions-with-distutils-and-mingw/
|
by: pion |
last post by:
Hello
I'm trying to make a web service client in python, and so to start out, I found this simple example that are supposed to parse an wsdl file using SOAPPy. I'm using Windows and got SOAPPy...
|
by: lllomh |
last post by:
Define the method first
this.state = {
buttonBackgroundColor: 'green',
isBlinking: false, // A new status is added to identify whether the button is blinking or not
}
autoStart=()=>{
|
by: DJRhino |
last post by:
Was curious if anyone else was having this same issue or not....
I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM)
The start time is equivalent to 19:00 (7PM) in Central...
|
by: Aliciasmith |
last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
|
by: NeoPa |
last post by:
Introduction
For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
|
by: Teri B |
last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course.
0ne-to-many. One course many roles.
Then I created a report based on the Course form and...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM)
Please note that the UK and Europe revert to winter time on...
|
by: nia12 |
last post by:
Hi there,
I am very new to Access so apologies if any of this is obvious/not clear.
I am creating a data collection tool for health care employees to complete. It consists of a number of...
|
by: NeoPa |
last post by:
Introduction
For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...
| |