|
This[^] article looks like a viable alternative
I are troll
|
|
|
|
|
1) Yes, but are you sure you don't want a Windows Scheduled Task?
2) Kinda sorta, as the article pointed out by Eddy suggests. That's how I do it.
3) Yes, but are you sure you don't want a Windows Scheduled Task?
|
|
|
|
|
Hi all,
I'm having a problem using DllImport in C# to call a C++ function.
C++ Header File:
DLLEXPORT int drawMarkupOnLine (int jobId, int lineNumber, short* line, int drawMode);
C++ Source File:
DLLEXPORT int drawMarkupOnLine (int jobId, int lineNumber, short* line, int drawMode)
{
...
}
==========================================
C# Source File:
[DllImport("vdrdll.dll", EntryPoint = @"?drawMarkupOnLine@@YAHHHPAFH@Z")]
unsafe static extern int drawMarkupOnLine(int jobId, int lineNumber, short* line, int drawMode);
...
short* scan0 = (short*)bmd.Scan0;
short* nextScanLine = scan0;
drawMarkupOnLine (0, i, nextScanLine, lca[i]);
==========================================
When I try to call the function, I get an EntryPointNotFoundException, with message, "Unable to find an entry point named '?drawMarkupOnLine@@YAHHHPAFH@Z' in DLL 'vdrdll.dll'."
I've tried various permutations of IntPtr, string pointers, and void pointers for the third parameter (which I'm assuming is causing the problem), but nothing seems to work. (Other functions with only int parameters work just fine.) Can someone suggest a reliable way to get this to link?
Thanks,
Alan
|
|
|
|
|
Hi Alan,
in C# one does not need unsafe nor short*, instead ref short would do.
since native C++ is mangling names, I suggest you try DllImport("vdrdll.dll", EntryPoint="...", ExactSpelling=true) , since maybe the marshaling is adding an A or W because of the pointer.
|
|
|
|
|
Thanks for the suggestion Luc, but I'm still getting the same result. It even happens when I use a simple local variable for the 3rd parameter.
|
|
|
|
|
It gets stranger: The problem still shows up even with all int parameters.
|
|
|
|
|
OK, I suggest you use DUMPBIN or some other tool to verify the symbols exported by your DLL file.
BTW: you are not getting confused (or confusing your tools) by having several copies of the DLL in different places, other folders, GAC, ...?
FWIW: I tend to use C, not C++, for native code, avoiding all name mangling. Never had such problems.
|
|
|
|
|
Thanks Luc. I got the symbol from the VdrDll.exp file (exports library file), which seems to work for the other exported functions.
I tried renaming the generated DLL, and got the expected missing module error message.
Yes, C would be simpler, but I'm trying to leverage a massive existing code base already in C++.
|
|
|
|
|
Hi Alan,
I did some experiments using VS2008 Express for both C++ and C# and all went well, here is the relevant code:
#define NATIVECPPEXPERIMENT_API __declspec(dllexport)
NATIVECPPEXPERIMENT_API int fint1(int arg1) {
return arg1*arg1;
}
NATIVECPPEXPERIMENT_API int fint4(int arg1,int arg2, short* arg3, int arg4) {
*arg3=(short)(arg1*arg2);
return arg1*arg4;
}
namespace ConsoleApplication1 {
class Program {
static void log(string s) {Console.WriteLine(s);}
static void Main(string[] args) {
int res1=cppfint1(12);
log("res1="+res1);
short shrt=14;
int res4=cppfint4(12,13,ref shrt, 15);
log("res4="+res4);
log("shrt="+shrt);
Console.ReadLine();
}
[DllImport("nativeCppExperiment.dll", EntryPoint="?fint1@@YAHH@Z")]
static extern int cppfint1(int arg1);
[DllImport("nativeCppExperiment.dll", EntryPoint="?fint4@@YAHHHPAFH@Z")]
static extern int cppfint4(int agr1, int arg2, ref short arg3, int arg4);
}
}
So either you are overlooking something, or your system is ill. I suggest you try closing and reopening Studio, and consider rebooting.
|
|
|
|
|
Thanks again for the help Luc! Your code looks perfect. This is what I tried to do with the ref parameter.
I've been experimenting, and taking out the EntryPoint clause allowed the linker to find the function:
[DllImport("vdrdll.dll")]
static unsafe extern void drawMarkupOnLine(int jobId, int lineNumber, short* line, int drawMode);
I don't understand why this worked. Now I'm getting a read/write-protected-memory exception, but this may just be a "normal" bug.
|
|
|
|
|
Alan Balkany wrote: taking out the EntryPoint clause allowed the linker to find the function
That is amazing, if not impossible. I've never read that should work.
I tried it for my second call, and I immediately got an EntryPointNotFoundException, as I was expecting.
namespace ConsoleApplication1 {
class Program {
static void log(string s) {Console.WriteLine(s);}
static void Main(string[] args) {
int res1=cppfint1(12);
log("res1="+res1);
short shrt=14;
int res4=fint4(12,13,ref shrt, 15);
log("res4="+res4);
log("shrt="+shrt);
Console.ReadLine();
}
[DllImport("nativeCppExperiment.dll", EntryPoint="?fint1@@YAHH@Z")]
static extern int cppfint1(int arg1);
[DllImport("nativeCppExperiment.dll")]
static extern int fint4(int agr1, int arg2, ref short arg3, int arg4);
}
}
Your system is acting weird if you ask me.
|
|
|
|
|
I took your advice and restarted the system, and did a Rebuild Solution on both halves. The results were the same; it links perfectly with the Entry Point left out for only that function.
"Your system is acting weird if you ask me."
I blame Microsoft.
|
|
|
|
|
|
could it be you have a C-version of that function somewhere?
or a hidden extern "C" { ... } around it?
|
|
|
|
|
Neither of those are present. (Looking around, I can see you've been busy today!)
Thanks again for the help!
|
|
|
|
|
No problem.
|
|
|
|
|
How do I access the data coming in and out of the USB Port on a PDA using C#. My PDA is not a host, but I should still be able to communicate with a Host. I do not want to use the Active Sync. Any help and code snippets would be greatly appreciated.
|
|
|
|
|
You can use SerialPort class or this library for communicating directly with Usb port: LibUsbDotNet[^]
|
|
|
|
|
Thanks for your prompt response.
Using the SerialPort class or the LibUsbDotNet works fine from the PC side, but not on the PDA. How do I read the USB info on a PDA using Windows Mobile?
|
|
|
|
|
function tes(){
var xmlSOAP = new ActiveXObject("MSXML2.DOMDocument");
chunkCompressed='apakah &apakah';
alert(chunkCompressed.length+" "+chunkCompressed );
var param='<?xml version="1.0" encoding="utf-8"?>'+
'<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">'+
'<soap:Body>'+
'<UploadData xmlns="http://tempuri.org/">'+
'<chunk xmlns:dt="urn:schemas-microsoft-com:datatypes" dt:dt="string">'+chunkCompressed+'</chunk>'+
'</UploadData>'+
'</soap:Body>'+
'</soap:Envelope>';
xmlSOAP.loadXML(param);
alert(param);
xmlSOAP.save("D:\\tes.xml");
my error in character &, how to solve the problem , so i can write & in my xml file, thx
regards
novhard
|
|
|
|
|
|
|
I don't know about the original poster, but I found that to be really helpful. Thanks
|
|
|
|
|
glad to help
|
|
|
|
|
thx for reply my message, i am oredy solve the problem too
thank you very much ..^.^
|
|
|
|
|