Click here to Skip to main content
15,886,519 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi following is the code example. Please suggest what should I do to call c++ written function to a c# function.
Thank you in advance
c++ code
// type defs. for Graphic Gemms Code - see later

#define BYTE_IMAGE

#ifdef BYTE_IMAGE
typedef unsigned char kz_pixel_t;        /* for 8 bit-per-pixel images */
#define uiNR_OF_GREY (256)
#else
typedef unsigned short kz_pixel_t;       /* for 12 bit-per-pixel images (default) */
# define uiNR_OF_GREY (4096)
#endif
static int CLAHE (kz_pixel_t* pImage, unsigned int uiXRes, unsigned int uiYRes,
         kz_pixel_t Min, kz_pixel_t Max, unsigned int uiNrX, unsigned int uiNrY,
              unsigned int uiNrBins, float fCliplimit)
 {
...
...
}

c# calling code
csharpfunction()
{
CLAHE((byte*)im, 0, 0, 0, 0, 0, 0, 0, 0.02);
}

im is image instance. the c++ code gets the pointer in byte formate. how can I convert the referece to my image object to pass in the function as byte*.
Please help will be very thankful to you.
Posted
Updated 20-Jul-11 22:55pm
v2
Comments
Stefan_Lang 21-Jul-11 4:56am    
I fixed the tags for you. Use the <pre> tag for code blocks, not the <code> tags.
marius_po 14-May-14 9:47am    
Hello, did you manage to get it to work ?

From what I understand, you need to create an assembly with you C++ code and then use the following:

http://msdn.microsoft.com/en-us/library/aa984739%28v=vs.71%29.aspx[^]

Im not 100% sure of this, but when using the Windows DLLs thats what I do.
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 21-Jul-11 12:10pm    
You could be sure, but don't call is assembly -- this is unmanaged DLL (will you fix it in your answer?). I voted 4.
--SA
What you can do is ....
Create a assembly of the c++ code and then
use it in C# by implementing Attributes in your C# code...

Try using DLLImport and then give the name of the DLL that you have created and then refer to that dll file this way in your C# code....

Happy Coding...
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 21-Jul-11 12:12pm    
My 4. Not "assembly", this is unmanaged DLL and P/Invoke.
--SA
DominicZA 21-Jul-11 13:02pm    
Awesome, now I have learned something!! If I could vote 5 on your comment, I would ;)
If image is a bitmap use msdn.microsoft.com/en-us/library/5ey6h79d.aspx just replace IntPtr wíth byte*.
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 21-Jul-11 12:13pm    
The idea is alternative and very good in case we understand what OP needs correctly. However, your answer is very hard to explain. Will you clarify it? You should explain that using C++ project can be avoided at all, using your idea.
--SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900