10 TIPs - To Become a Good Developer/Programmer
Why Join
Become a member
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
C# Corner Home
Technologies
Monthly Leaders
ASK A QUESTION
Forum guidelines
Arijeet Ghosh
1.9k
205
20.9k
Marshaling code2 : Problem described below
Jul 1 2020 7:32 AM
Though I don't know VC++ have I've searched the net. Please check it...
The VC++ code:-
a)plus.h:
#ifndef PLUS_H
#define PLUS_H
int
__declspec
(
dllexport
) add(
int
a,
int
b);
#endif
b)plus.cpp:
#include "pch.h"
#include "plus.h"
int
add(
int
a,
int
b)
{
return
a + b;
}
Now in C#
public
partial
class
Form1 : Form
{
public
Form1()
{
InitializeComponent();
}
private
void
button1_Click(
object
sender, EventArgs e)
{
Test t =
new
Test();
int
fooPtr = Test.add(5, 9);
int
LENGTH = 1;
var foo =
new
int
[LENGTH];
/// Marshal.Copy(fooPtr, foo, 0, LENGTH);
MessageBox.Show(fooPtr.ToString());
}
}
public
class
Test
{
[DllImport(
"F:/TestMultipleProject/FirstDll/Debug/FirstDll.dll"
, CharSet = CharSet.Ansi, SetLastError =
true
, ExactSpelling =
true
, CallingConvention = CallingConvention.Cdecl)]
public
static
extern
int
add(
int
a,
int
b);
}
Reference of VC ++ project is added to C# and they both reside in same solution
NOW PROBLEM is unable to find an entry point named add in the dll....
Reply
Answers (
0
)
I have written the code but still comes error
Bar code instead text in column c#