DLL NotSupportedException

J

Jack P

Hi All,
I am new to DLL, I created a native DLL for Windows application (windows
xp/vista...), it works.

I tried to implement same thing to compact framework ( for windows
mobile/ppc), but can't get work yet...

The run time error is NotSupportedException, but the same thing in windows
application are working fine...

I can see this in my stdafx.h
#define WINVER _WIN32_WCE

so I think it should be right for config but ... still can't work.

Please help.

Thanks.

JB.




The managed code to use DLL:
////////////////////////////
namespace JBDlltest
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
double xy = ImplementNativeDll.Add(6.0, 5.0); //////////////
will happen NotSupportedException
}

}

public class ImplementNativeDll
{

[DllImport(@"C:\Users\JB\Documents\Visual Studio
2008\Projects\dllll\dllll\Windows Mobile 5.0 Pocket PC SDK
(ARMV4I)\Debug\dllll.dll", EntryPoint = "Add")]
public static extern double Add(double x, double y);
}
}

and

The native DLL:
/////////////////////////////////////////////////
#include "stdafx.h"

extern "C" __declspec(dllexport) double Add(double x, double y);

__declspec(dllexport) double Add(double x, double y)

{

return (x*y);

}
 
C

Chris Tacke, eMVP

You can't create a managed C++ assembly for CE, it's not supported. Not
sure how you even got to a project that you think might create one.

If it's strictly a native DLL, make sure you built it for the right
processor.


--

Chris Tacke, Embedded MVP
OpenNETCF Consulting
Giving back to the embedded community
http://community.OpenNETCF.com
 
J

Jack P

I found one doucmentation:
http://support.microsoft.com/?scid=kb;en-us;241531&x=21&y=15

and here is my code, and result is as expected => CAN'T WORK.

///////////////////////////
[DllImport("CProcess.DLL", EntryPoint = "WinExecCE")]
public static extern long WinExecCE(string a, string b);
public Form1()
{
InitializeComponent();
}

private void Form1_Load(object sender, EventArgs e)
{
long a = WinExecCE("Calc.exe", "");
}
///////////////////////////

I don't know where is wrong ?.

I almost try ANY thing I can do in whatever configurations ( processor,
release / debug ... )

.... Please help..

JB.




Chris Tacke said:
You can't create a managed C++ assembly for CE, it's not supported. Not
sure how you even got to a project that you think might create one.

If it's strictly a native DLL, make sure you built it for the right
processor.


--

Chris Tacke, Embedded MVP
OpenNETCF Consulting
Giving back to the embedded community
http://community.OpenNETCF.com



Jack P said:
Hi All,
I am new to DLL, I created a native DLL for Windows application (windows
xp/vista...), it works.

I tried to implement same thing to compact framework ( for windows
mobile/ppc), but can't get work yet...

The run time error is NotSupportedException, but the same thing in
windows application are working fine...

I can see this in my stdafx.h
#define WINVER _WIN32_WCE

so I think it should be right for config but ... still can't work.

Please help.

Thanks.

JB.




The managed code to use DLL:
////////////////////////////
namespace JBDlltest
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
double xy = ImplementNativeDll.Add(6.0, 5.0); //////////////
will happen NotSupportedException
}

}

public class ImplementNativeDll
{

[DllImport(@"C:\Users\JB\Documents\Visual Studio
2008\Projects\dllll\dllll\Windows Mobile 5.0 Pocket PC SDK
(ARMV4I)\Debug\dllll.dll", EntryPoint = "Add")]
public static extern double Add(double x, double y);
}
}

and

The native DLL:
/////////////////////////////////////////////////
#include "stdafx.h"

extern "C" __declspec(dllexport) double Add(double x, double y);

__declspec(dllexport) double Add(double x, double y)

{

return (x*y);

}
 
C

Chris Tacke, eMVP

It returns a 32-bit DWORD. A managed 32-bit is an int, not a long.


--

Chris Tacke, Embedded MVP
OpenNETCF Consulting
Giving back to the embedded community
http://community.OpenNETCF.com

Jack P said:
I found one doucmentation:
http://support.microsoft.com/?scid=kb;en-us;241531&x=21&y=15

and here is my code, and result is as expected => CAN'T WORK.

///////////////////////////
[DllImport("CProcess.DLL", EntryPoint = "WinExecCE")]
public static extern long WinExecCE(string a, string b);
public Form1()
{
InitializeComponent();
}

private void Form1_Load(object sender, EventArgs e)
{
long a = WinExecCE("Calc.exe", "");
}
///////////////////////////

I don't know where is wrong ?.

I almost try ANY thing I can do in whatever configurations ( processor,
release / debug ... )

... Please help..

JB.




Chris Tacke said:
You can't create a managed C++ assembly for CE, it's not supported. Not
sure how you even got to a project that you think might create one.

If it's strictly a native DLL, make sure you built it for the right
processor.


--

Chris Tacke, Embedded MVP
OpenNETCF Consulting
Giving back to the embedded community
http://community.OpenNETCF.com



Jack P said:
Hi All,
I am new to DLL, I created a native DLL for Windows application (windows
xp/vista...), it works.

I tried to implement same thing to compact framework ( for windows
mobile/ppc), but can't get work yet...

The run time error is NotSupportedException, but the same thing in
windows application are working fine...

I can see this in my stdafx.h
#define WINVER _WIN32_WCE

so I think it should be right for config but ... still can't work.

Please help.

Thanks.

JB.




The managed code to use DLL:
////////////////////////////
namespace JBDlltest
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
double xy = ImplementNativeDll.Add(6.0, 5.0); //////////////
will happen NotSupportedException
}

}

public class ImplementNativeDll
{

[DllImport(@"C:\Users\JB\Documents\Visual Studio
2008\Projects\dllll\dllll\Windows Mobile 5.0 Pocket PC SDK
(ARMV4I)\Debug\dllll.dll", EntryPoint = "Add")]
public static extern double Add(double x, double y);
}
}

and

The native DLL:
/////////////////////////////////////////////////
#include "stdafx.h"

extern "C" __declspec(dllexport) double Add(double x, double y);

__declspec(dllexport) double Add(double x, double y)

{

return (x*y);

}
 
J

Jack P

I changed to Int, result is the still fail.

public partial class Form1 : Form
{
[DllImport("CProcess.dll")]
public static extern int WinExecCE(string a, string b);


public Form1()
{
InitializeComponent();
}

private void Form1_Load(object sender, EventArgs e)
{
int a = WinExecCE("Calc.exe", "");
}
}

I can't understand Microsoft put so much black box in compact framework, why
NOT just put the REAL working source code in website for download and verify
.. that's easier and useful.

try and error everyday is really boring stuff.

I can do something in unmanaged code then I just can't do anything in
managed code ...


Thanks.

Chris Tacke said:
It returns a 32-bit DWORD. A managed 32-bit is an int, not a long.


--

Chris Tacke, Embedded MVP
OpenNETCF Consulting
Giving back to the embedded community
http://community.OpenNETCF.com

Jack P said:
I found one doucmentation:
http://support.microsoft.com/?scid=kb;en-us;241531&x=21&y=15

and here is my code, and result is as expected => CAN'T WORK.

///////////////////////////
[DllImport("CProcess.DLL", EntryPoint = "WinExecCE")]
public static extern long WinExecCE(string a, string b);
public Form1()
{
InitializeComponent();
}

private void Form1_Load(object sender, EventArgs e)
{
long a = WinExecCE("Calc.exe", "");
}
///////////////////////////

I don't know where is wrong ?.

I almost try ANY thing I can do in whatever configurations ( processor,
release / debug ... )

... Please help..

JB.




Chris Tacke said:
You can't create a managed C++ assembly for CE, it's not supported. Not
sure how you even got to a project that you think might create one.

If it's strictly a native DLL, make sure you built it for the right
processor.


--

Chris Tacke, Embedded MVP
OpenNETCF Consulting
Giving back to the embedded community
http://community.OpenNETCF.com



Hi All,
I am new to DLL, I created a native DLL for Windows application
(windows xp/vista...), it works.

I tried to implement same thing to compact framework ( for windows
mobile/ppc), but can't get work yet...

The run time error is NotSupportedException, but the same thing in
windows application are working fine...

I can see this in my stdafx.h
#define WINVER _WIN32_WCE

so I think it should be right for config but ... still can't work.

Please help.

Thanks.

JB.




The managed code to use DLL:
////////////////////////////
namespace JBDlltest
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
double xy = ImplementNativeDll.Add(6.0, 5.0); //////////////
will happen NotSupportedException
}

}

public class ImplementNativeDll
{

[DllImport(@"C:\Users\JB\Documents\Visual Studio
2008\Projects\dllll\dllll\Windows Mobile 5.0 Pocket PC SDK
(ARMV4I)\Debug\dllll.dll", EntryPoint = "Add")]
public static extern double Add(double x, double y);
}
}

and

The native DLL:
/////////////////////////////////////////////////
#include "stdafx.h"

extern "C" __declspec(dllexport) double Add(double x, double y);

__declspec(dllexport) double Add(double x, double y)

{

return (x*y);

}
 
P

Peter Foot

Okay, going back to basics what are you actually trying to achieve this this
code? Do you want to launch the calculator application?

Peter

--
Peter Foot
Microsoft Device Application Development MVP
peterfoot.net | appamundi.com | inthehand.com
APPA Mundi Ltd - software solutions for a mobile world
In The Hand Ltd - .NET Components for Mobility

Jack P said:
I changed to Int, result is the still fail.

public partial class Form1 : Form
{
[DllImport("CProcess.dll")]
public static extern int WinExecCE(string a, string b);


public Form1()
{
InitializeComponent();
}

private void Form1_Load(object sender, EventArgs e)
{
int a = WinExecCE("Calc.exe", "");
}
}

I can't understand Microsoft put so much black box in compact framework,
why NOT just put the REAL working source code in website for download and
verify . that's easier and useful.

try and error everyday is really boring stuff.

I can do something in unmanaged code then I just can't do anything in
managed code ...


Thanks.

Chris Tacke said:
It returns a 32-bit DWORD. A managed 32-bit is an int, not a long.


--

Chris Tacke, Embedded MVP
OpenNETCF Consulting
Giving back to the embedded community
http://community.OpenNETCF.com

Jack P said:
I found one doucmentation:
http://support.microsoft.com/?scid=kb;en-us;241531&x=21&y=15

and here is my code, and result is as expected => CAN'T WORK.

///////////////////////////
[DllImport("CProcess.DLL", EntryPoint = "WinExecCE")]
public static extern long WinExecCE(string a, string b);
public Form1()
{
InitializeComponent();
}

private void Form1_Load(object sender, EventArgs e)
{
long a = WinExecCE("Calc.exe", "");
}
///////////////////////////

I don't know where is wrong ?.

I almost try ANY thing I can do in whatever configurations ( processor,
release / debug ... )

... Please help..

JB.




"Chris Tacke, eMVP" <ctacke.at.opennetcf.dot.com> wrote in message
You can't create a managed C++ assembly for CE, it's not supported.
Not sure how you even got to a project that you think might create one.

If it's strictly a native DLL, make sure you built it for the right
processor.


--

Chris Tacke, Embedded MVP
OpenNETCF Consulting
Giving back to the embedded community
http://community.OpenNETCF.com



Hi All,
I am new to DLL, I created a native DLL for Windows application
(windows xp/vista...), it works.

I tried to implement same thing to compact framework ( for windows
mobile/ppc), but can't get work yet...

The run time error is NotSupportedException, but the same thing in
windows application are working fine...

I can see this in my stdafx.h
#define WINVER _WIN32_WCE

so I think it should be right for config but ... still can't work.

Please help.

Thanks.

JB.




The managed code to use DLL:
////////////////////////////
namespace JBDlltest
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
double xy = ImplementNativeDll.Add(6.0, 5.0);
////////////// will happen NotSupportedException
}

}

public class ImplementNativeDll
{

[DllImport(@"C:\Users\JB\Documents\Visual Studio
2008\Projects\dllll\dllll\Windows Mobile 5.0 Pocket PC SDK
(ARMV4I)\Debug\dllll.dll", EntryPoint = "Add")]
public static extern double Add(double x, double y);
}
}

and

The native DLL:
/////////////////////////////////////////////////
#include "stdafx.h"

extern "C" __declspec(dllexport) double Add(double x, double y);

__declspec(dllexport) double Add(double x, double y)

{

return (x*y);

}
 
C

Chris Tacke, eMVP

It's not a black box at all. It's all very, very well documented. If this
isn't working it's because *you* are doing something wrong, not becasue of
some global Microsoft conspiracy to prevent you from doing it. What is the
old addage about the mechanic who blames his tools?

What you need to do at this point is:

1. Make sure that your native project is a Smart Device project (not a
desktop project) and that it is targeting the right processor.
2. Use dumpbin and make sure that you are actually exporting the function
you think you are and that the name is unmangled.
3. Make sure that the native DLL is eitehr in the device's \Windows folder
or in the application folder
4. Make sure that your managed application is actually on the target device
(I've had times where one project was pushing to an emulator and the other
to a device, or to two separate emulators).


--

Chris Tacke, Embedded MVP
OpenNETCF Consulting
Giving back to the embedded community
http://community.OpenNETCF.com



Jack P said:
I changed to Int, result is the still fail.

public partial class Form1 : Form
{
[DllImport("CProcess.dll")]
public static extern int WinExecCE(string a, string b);


public Form1()
{
InitializeComponent();
}

private void Form1_Load(object sender, EventArgs e)
{
int a = WinExecCE("Calc.exe", "");
}
}

I can't understand Microsoft put so much black box in compact framework,
why NOT just put the REAL working source code in website for download and
verify . that's easier and useful.

try and error everyday is really boring stuff.

I can do something in unmanaged code then I just can't do anything in
managed code ...


Thanks.

Chris Tacke said:
It returns a 32-bit DWORD. A managed 32-bit is an int, not a long.


--

Chris Tacke, Embedded MVP
OpenNETCF Consulting
Giving back to the embedded community
http://community.OpenNETCF.com

Jack P said:
I found one doucmentation:
http://support.microsoft.com/?scid=kb;en-us;241531&x=21&y=15

and here is my code, and result is as expected => CAN'T WORK.

///////////////////////////
[DllImport("CProcess.DLL", EntryPoint = "WinExecCE")]
public static extern long WinExecCE(string a, string b);
public Form1()
{
InitializeComponent();
}

private void Form1_Load(object sender, EventArgs e)
{
long a = WinExecCE("Calc.exe", "");
}
///////////////////////////

I don't know where is wrong ?.

I almost try ANY thing I can do in whatever configurations ( processor,
release / debug ... )

... Please help..

JB.




"Chris Tacke, eMVP" <ctacke.at.opennetcf.dot.com> wrote in message
You can't create a managed C++ assembly for CE, it's not supported.
Not sure how you even got to a project that you think might create one.

If it's strictly a native DLL, make sure you built it for the right
processor.


--

Chris Tacke, Embedded MVP
OpenNETCF Consulting
Giving back to the embedded community
http://community.OpenNETCF.com



Hi All,
I am new to DLL, I created a native DLL for Windows application
(windows xp/vista...), it works.

I tried to implement same thing to compact framework ( for windows
mobile/ppc), but can't get work yet...

The run time error is NotSupportedException, but the same thing in
windows application are working fine...

I can see this in my stdafx.h
#define WINVER _WIN32_WCE

so I think it should be right for config but ... still can't work.

Please help.

Thanks.

JB.




The managed code to use DLL:
////////////////////////////
namespace JBDlltest
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
double xy = ImplementNativeDll.Add(6.0, 5.0);
////////////// will happen NotSupportedException
}

}

public class ImplementNativeDll
{

[DllImport(@"C:\Users\JB\Documents\Visual Studio
2008\Projects\dllll\dllll\Windows Mobile 5.0 Pocket PC SDK
(ARMV4I)\Debug\dllll.dll", EntryPoint = "Add")]
public static extern double Add(double x, double y);
}
}

and

The native DLL:
/////////////////////////////////////////////////
#include "stdafx.h"

extern "C" __declspec(dllexport) double Add(double x, double y);

__declspec(dllexport) double Add(double x, double y)

{

return (x*y);

}
 
C

Christopher Fairbairn [MVP]

Hi Jack,

Jack P said:
I can't understand Microsoft put so much black box in compact framework

try and error everyday is really boring stuff.

No platform is a magic bullet. You need to invest the time to learn the
specifics of the environment and its related development tools. I doubt
you'll find Android, iPhone, Symbian or Blackberry significantly different
in this regard..

As Peter mentioned it would also help if you clearly spelt out what you are
attempting to acheive. One code sample you posted showed a C++ calculator
type API, while the present one references an old eVB sample for launching
applications. What is you're desired outcome?

I assume you are wanting to learn how to implement Platform Invoke calls
into C/C++ code you are going to write. As Chris Tacke pointed out, your
difficulty is probably related to one of two things:

A) Knowing how to correctly build your native DLL so it exposes the function
in a compatable form

B) Knowing how to correctly deploy both the native and managed parts of your
application to the emulator/device

To help you along the way I went through the old eVB example you mentioned
and created a Visual Studio 2008 / .NET CF 3.5 project which demonstrates
the same thing.

You can download the source code at
http://www.christec.co.nz/blog/wp-content/uploads/2009/04/oldpinvokeexample.zip.
Hopefully you will be able to set both projects to deploy to the same device
and see that clicking the button in the managed app launches the calendar
application via the native DLL (although using the
System.Diagnostics.Process class would be a better solution for this
specific task).

If you have any difficulty deploying the project(s) we should be able to
work through them.

Hope this helps,
Christopher Fairbairn
 
J

Jack P

Hi all,
I have done it finally.

I think the difficulty is just a little lower than Cage finding his
treasure.

Cheers!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top