473,395 Members | 1,972 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.

Getting an error that entry point can not be located from my pinvo

I'm trying to pinvoke a function in a C++ dll but I'm getting an error that
entry point can not be located from my pinvoke code. Do I need to add any
code to the C++ DLL to make the pinvoke? The following is what I have in my
C# code:

[DllImport("PropSheetHost.dll")]
public static extern void ShowAdProp(
[MarshalAs(UnmanagedType.LPStr)]
String m);

//This is where I invoke the function
private void propertyToolStripMenuItem_Click(object sender,
EventArgs e)
{

ShowAdProp("'CN=1608,CN=Users,CN=Accounting,CN=Con texts,CN=Unity,CN=Symark,CN=Program Data,DC=unity,DC=windev,DC=symark,DC=com");
}

//This is start of the C++ dll
using namespace std;

void ShowAdProp(wstring adPath)
{

CoInitialize(NULL);

HRESULT hr;

HINSTANCE hInstance = NULL;
HWND hwndConsole = GetConsoleWindow();
if(hwndConsole)
{
hInstance = (HINSTANCE)(LONG_PTR)GetWindowLongPtr(hwndConsole,
GWLP_HINSTANCE);
}

CPropSheetHost *pHost = new CPropSheetHost(hInstance);

// Hold a reference count for the CPropSheetHost object.
pHost->AddRef();

hr = pHost->SetObject(adPath.c_str());

--
Thanks.
Jul 12 '06 #1
5 3560
>Do I need to add any
>code to the C++ DLL to make the pinvoke?
Not add but change. The parameter type can't be a wstring, it must be
a library neutral type such as a char*. You must also ensure you're
using the right calling convention and check under which name the
function is exported (it may be mangled).
Mattias

--
Mattias Sjögren [C# MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
Jul 12 '06 #2
Thank you for the reply. Here is what I've modified but I'm still getting
the same error message.
//The header file
public:
HRESULT SetObject(LPCWSTR pwszADsPath);
HRESULT SetObject(IADs *pads);
__declspec(dllexport) void ShowAdProp(WCHAR* inPath);
void Run();
//The function I'm exporting
void ShowAdProp(WCHAR* inPath)
{
wstring adPath = inPath;

CoInitialize(NULL);

HRESULT hr;

HINSTANCE hInstance = NULL;
HWND hwndConsole = GetConsoleWindow();
if(hwndConsole)
{
hInstance = (HINSTANCE)(LONG_PTR)GetWindowLongPtr(hwndConsole,
GWLP_HINSTANCE);
}

CPropSheetHost *pHost = new CPropSheetHost(hInstance);

// Hold a reference count for the CPropSheetHost object.
pHost->AddRef();

hr = pHost->SetObject(adPath.c_str());
if(FAILED(hr))
{
goto ExitMain;
}

pHost->Run();

/*
Release the CPropSheetHost object. Other components may still hold a
reference to the object, so this cannot just be deleted here. Let
the object delete itself when all references are released.
*/
pHost->Release();
ExitMain:

CoUninitialize();
}

//My import statement
namespace ppGlobal
{
public partial class FormMain : Form
{
[DllImport("PropSheetHost.dll")]
public static extern void ShowAdProp(
[MarshalAs(UnmanagedType.LPWStr)]
String m);

//Invoke statement
private void propertyToolStripMenuItem_Click(object sender,
EventArgs e)
{

ShowAdProp("'CN=1608,CN=Users,CN=Accounting,CN=Con texts,CN=Unity,CN=Symark,CN=Program Data,DC=unity,DC=windev,DC=symark,DC=com");
}

//Error Message
An unhandled exception of type 'System.EntryPointNotFoundException' occurred
in ppGlobal.exe

Additional information: Unable to find an entry point named 'ShowAdProp' in
DLL 'PropSheetHost.dll'.
--
Thanks.
"Mattias Sjögren" wrote:
Do I need to add any
code to the C++ DLL to make the pinvoke?

Not add but change. The parameter type can't be a wstring, it must be
a library neutral type such as a char*. You must also ensure you're
using the right calling convention and check under which name the
function is exported (it may be mangled).
Mattias

--
Mattias Sjögren [C# MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
Jul 12 '06 #3
The PInvoke marshaler cannot marshal a String to a std::wstring object.
Change your C++ code and make the argument a simple ascii string or a
wchar_t string.
Willy.

"Pucca" <Pu***@discussions.microsoft.comwrote in message
news:20**********************************@microsof t.com...
| I'm trying to pinvoke a function in a C++ dll but I'm getting an error
that
| entry point can not be located from my pinvoke code. Do I need to add any
| code to the C++ DLL to make the pinvoke? The following is what I have in
my
| C# code:
|
| [DllImport("PropSheetHost.dll")]
| public static extern void ShowAdProp(
| [MarshalAs(UnmanagedType.LPStr)]
| String m);
|
| //This is where I invoke the function
| private void propertyToolStripMenuItem_Click(object sender,
| EventArgs e)
| {
|
|
ShowAdProp("'CN=1608,CN=Users,CN=Accounting,CN=Con texts,CN=Unity,CN=Symark,CN=Program
Data,DC=unity,DC=windev,DC=symark,DC=com");
| }
|
| //This is start of the C++ dll
| using namespace std;
|
| void ShowAdProp(wstring adPath)
| {
|
| CoInitialize(NULL);
|
| HRESULT hr;
|
| HINSTANCE hInstance = NULL;
| HWND hwndConsole = GetConsoleWindow();
| if(hwndConsole)
| {
| hInstance = (HINSTANCE)(LONG_PTR)GetWindowLongPtr(hwndConsole,
| GWLP_HINSTANCE);
| }
|
| CPropSheetHost *pHost = new CPropSheetHost(hInstance);
|
| // Hold a reference count for the CPropSheetHost object.
| pHost->AddRef();
|
| hr = pHost->SetObject(adPath.c_str());
|
| --
| Thanks.
Jul 14 '06 #4
Thank you and I did that as follow but I'm still getting the same error
message.
__declspec(dllexport) void ShowAdProp(WCHAR* inPath)
--
Thanks.
"Willy Denoyette [MVP]" wrote:
The PInvoke marshaler cannot marshal a String to a std::wstring object.
Change your C++ code and make the argument a simple ascii string or a
wchar_t string.
Willy.

"Pucca" <Pu***@discussions.microsoft.comwrote in message
news:20**********************************@microsof t.com...
| I'm trying to pinvoke a function in a C++ dll but I'm getting an error
that
| entry point can not be located from my pinvoke code. Do I need to add any
| code to the C++ DLL to make the pinvoke? The following is what I have in
my
| C# code:
|
| [DllImport("PropSheetHost.dll")]
| public static extern void ShowAdProp(
| [MarshalAs(UnmanagedType.LPStr)]
| String m);
|
| //This is where I invoke the function
| private void propertyToolStripMenuItem_Click(object sender,
| EventArgs e)
| {
|
|
ShowAdProp("'CN=1608,CN=Users,CN=Accounting,CN=Con texts,CN=Unity,CN=Symark,CN=Program
Data,DC=unity,DC=windev,DC=symark,DC=com");
| }
|
| //This is start of the C++ dll
| using namespace std;
|
| void ShowAdProp(wstring adPath)
| {
|
| CoInitialize(NULL);
|
| HRESULT hr;
|
| HINSTANCE hInstance = NULL;
| HWND hwndConsole = GetConsoleWindow();
| if(hwndConsole)
| {
| hInstance = (HINSTANCE)(LONG_PTR)GetWindowLongPtr(hwndConsole,
| GWLP_HINSTANCE);
| }
|
| CPropSheetHost *pHost = new CPropSheetHost(hInstance);
|
| // Hold a reference count for the CPropSheetHost object.
| pHost->AddRef();
|
| hr = pHost->SetObject(adPath.c_str());
|
| --
| Thanks.
Jul 17 '06 #5
I'm guessing that the name gets mangled. Check to make sure that the
exported name is really ShowAdProc (by using depends.exe for instance). You
also need to change your MarshalAs statement in the DllImport to
UnmanagedTypes.LPWStr.

/claes
"Pucca" <Pu***@discussions.microsoft.comwrote in message
news:FF**********************************@microsof t.com...
Thank you and I did that as follow but I'm still getting the same error
message.
__declspec(dllexport) void ShowAdProp(WCHAR* inPath)
--
Thanks.
"Willy Denoyette [MVP]" wrote:
>The PInvoke marshaler cannot marshal a String to a std::wstring object.
Change your C++ code and make the argument a simple ascii string or a
wchar_t string.
Willy.

"Pucca" <Pu***@discussions.microsoft.comwrote in message
news:20**********************************@microso ft.com...
| I'm trying to pinvoke a function in a C++ dll but I'm getting an error
that
| entry point can not be located from my pinvoke code. Do I need to add
any
| code to the C++ DLL to make the pinvoke? The following is what I have
in
my
| C# code:
|
| [DllImport("PropSheetHost.dll")]
| public static extern void ShowAdProp(
| [MarshalAs(UnmanagedType.LPStr)]
| String m);
|
| //This is where I invoke the function
| private void propertyToolStripMenuItem_Click(object sender,
| EventArgs e)
| {
|
|
ShowAdProp("'CN=1608,CN=Users,CN=Accounting,CN=Co ntexts,CN=Unity,CN=Symark,CN=Program
Data,DC=unity,DC=windev,DC=symark,DC=com");
| }
|
| //This is start of the C++ dll
| using namespace std;
|
| void ShowAdProp(wstring adPath)
| {
|
| CoInitialize(NULL);
|
| HRESULT hr;
|
| HINSTANCE hInstance = NULL;
| HWND hwndConsole = GetConsoleWindow();
| if(hwndConsole)
| {
| hInstance = (HINSTANCE)(LONG_PTR)GetWindowLongPtr(hwndConsole,
| GWLP_HINSTANCE);
| }
|
| CPropSheetHost *pHost = new CPropSheetHost(hInstance);
|
| // Hold a reference count for the CPropSheetHost object.
| pHost->AddRef();
|
| hr = pHost->SetObject(adPath.c_str());
|
| --
| Thanks.

Jul 18 '06 #6

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

Similar topics

1
by: Sanju | last post by:
Hi.. I have working on Windows XP Operating System.Installed J2sdk 1.4.07 and installed IBM DB2 UDB version 8.1 Then i got the following error.. The procedure entry point SQLPrepareW@12...
8
by: Rod | last post by:
I have been working with ASP.NET 1.1 for quite a while now. For some reason, opening some ASP.NET applications we wrote is producing the following error message: "The Web server reported...
4
by: Allan M. Bruce | last post by:
I have a small implementation of a queue which I am trying to get to compile but cant figure out why it doesnt work. I have copied the minimum compilable code below. On gcc I get temp2.c: In...
4
by: martigras911 | last post by:
Hi, Every time I open 2003 Outlook, I get this error message "The procedure entry point LdrLockLoaderLock could not be located in the dynamic link library ntdll.dll" Please advise on how to fix...
23
by: deathtospam | last post by:
A day or two ago, I wrote a quick ASPX page with a CS codebehind using Visual Studio .NET 2005 -- it worked, I saved it and closed the project. Today, I came back to the project, reopened the...
2
by: Rymfax | last post by:
I have an application that will be used on both XP and Vista. One of the things this application needs to do is determine the exact operating system it is on. To get the correct "flavor" of Vista...
2
by: =?Utf-8?B?U3RldmVTNjA=?= | last post by:
I apparently made an unknown error. Now when I attempt to install two software packages I receive error messages. One package results in the message "The procedure entry point CallWindowProMF...
0
banning
by: banning | last post by:
hi i've been trying all day to install soap and its getting really annoying... the extension_dir is set up correctly... i have written in my ini file extension=php_soap.dll and there is a file that...
2
DonRayner
by: DonRayner | last post by:
This one has me stumped. I'm getting a "Type Mismatch" error on one of my forms when it's being opened. It's hapening before the forms "On Open" event, I stuck a msgbox in there to check and I'm...
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...
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
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
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.