TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Sunny Wang
NA
4
2.1k
lib wrapped into dll imported function access memory error
Dec 8 2014 11:46 PM
I have a lib file need to use in c#, I have wrapped it into dll, but when I call one of the function, it always show me the error of "attempted to read or write protected memory".
the function in lib header file is as the following
LONG WINAPI mdRandREx( LONG, LONG, LONG, LPVOID, LPVOID, LONG );
In c++ I wrapped it as the following
long MmdRandREx(long path,long netno,long stno,long dev[],short *buf,long bufsize)
{
buf=(short *)malloc(bufsize);
return mdRandREx(path,netno,stno,dev,buf,bufsize);
}
in c# I import it
[DllImport(@dllname, CallingConvention = CallingConvention.Cdecl)]
static extern long MmdRandREx(long path, long netno, long stno, long[] dev, out short buf, long bufsize);
and call it
short buf;
long retval=MmdRandREx(path,1, stanoPLC, dev1,out buf, bufsize);
I need to use this function to read PLC input and another function to write PLC access a PCI card.
can any one help me on this?
thanks in advance.
Reply
Answers (
2
)
Static Extension Methods Already Exist Error:
Shadow Detection