Click here to Skip to main content
15,923,557 members
Home / Discussions / Managed C++/CLI
   

Managed C++/CLI

 
GeneralRe: C++/CLI being used with VB and VC++ Pin
Shadowsoal15-Jul-09 4:13
Shadowsoal15-Jul-09 4:13 
GeneralRe: C++/CLI being used with VB and VC++ Pin
Shadowsoal15-Jul-09 5:21
Shadowsoal15-Jul-09 5:21 
GeneralRe: C++/CLI being used with VB and VC++ Pin
N a v a n e e t h15-Jul-09 17:49
N a v a n e e t h15-Jul-09 17:49 
GeneralRe: C++/CLI being used with VB and VC++ Pin
Shadowsoal15-Jul-09 17:52
Shadowsoal15-Jul-09 17:52 
GeneralRe: C++/CLI being used with VB and VC++ Pin
N a v a n e e t h15-Jul-09 18:23
N a v a n e e t h15-Jul-09 18:23 
QuestionNeed to call C++ function callback from C code in a Windows Form app Pin
KawiRider13-Jul-09 15:44
KawiRider13-Jul-09 15:44 
AnswerRe: Need to call C++ function callback from C code in a Windows Form app Pin
Mark Salsbery14-Jul-09 6:48
Mark Salsbery14-Jul-09 6:48 
GeneralRe: Need to call C++ function callback from C code in a Windows Form app Pin
KawiRider14-Jul-09 8:59
KawiRider14-Jul-09 8:59 
Hi,

Thanks for your reply. I apologize but I forgot to specify that we are actually using a .lib instead. I did, however, start a new project as a Win32 DLL and "successfully" generated a .dll. I use the term "successfully" loosely because although after making your suggested changes and hopefully configuring the .dll correctly, my program compiles flawlessly but at run-time I get the error
<br />
An unhandled exception of type 'System.Runtime.InteropServices.SEHException' occurred in driver.exe<br />
<br />
Additional information: External component has thrown an exception.<br />

On this line:
int retval = CFunction("Dummy path", FuncDelegate);


I've been scouring the net for resources on creating a C dll (though ideally I'd rather use the lib that was provided to us) and it appears as if I'm doing it correctly.

My_C_Dll.c
#include "My_C_Dll.h"

__declspec(dllexport) int __cdecl CFunction(char *src_path,void (*func)(const char *, int))
{	
    if (func != NULL)
    {
		func("Test String", 1);
    }
    
    return 1;
}

My_C_Dll.h
<code>
#ifdef __cplusplus
extern "C" {
#endif
</code>
#include <stdlib.h>
#include <stdio.h>
#include <windows.h>

	__declspec(dllexport) int __cdecl CFunction(char *src_path,void (*func)(const char *,int ));
<code>
#ifdef __cplusplus
}
#endif
</code>


Additionally, I placed these lines:
delegate void FuncCallbackDelegate(String^ str, int status);
		
[DllImport("My_C_Dll.dll", CharSet = CharSet::Ansi, CallingConvention = CallingConvention::StdCall)]
extern "C" int CFunction(String ^src_path, FuncCallbackDelegate ^del);

directly below all of the using namespace ... and right above the Form1 class definition.



Again, thank you for taking the time to provide assistance.
GeneralRe: Need to call C++ function callback from C code in a Windows Form app Pin
Mark Salsbery14-Jul-09 9:49
Mark Salsbery14-Jul-09 9:49 
GeneralRe: Need to call C++ function callback from C code in a Windows Form app Pin
KawiRider14-Jul-09 12:13
KawiRider14-Jul-09 12:13 
GeneralRe: Need to call C++ function callback from C code in a Windows Form app Pin
Daniel Grunwald20-Jul-09 4:47
Daniel Grunwald20-Jul-09 4:47 
QuestionSample for migrating C++ console app Pin
alleyes13-Jul-09 7:52
professionalalleyes13-Jul-09 7:52 
AnswerRe: Sample for migrating C++ console app Pin
Randor 14-Jul-09 11:24
professional Randor 14-Jul-09 11:24 
GeneralRe: Sample for migrating C++ console app Pin
alleyes15-Jul-09 2:24
professionalalleyes15-Jul-09 2:24 
QuestionPlease Help -- Link Error in Managed Wrapper Pin
Bharat Mallapur11-Jul-09 8:55
Bharat Mallapur11-Jul-09 8:55 
AnswerRe: Please Help -- Link Error in Managed Wrapper Pin
Bharat Mallapur13-Jul-09 23:14
Bharat Mallapur13-Jul-09 23:14 
QuestionMixed DLL Pin
cherrymotion10-Jul-09 5:29
cherrymotion10-Jul-09 5:29 
AnswerRe: Mixed DLL Pin
Richard Andrew x6414-Jul-09 20:12
professionalRichard Andrew x6414-Jul-09 20:12 
QuestionCEdit Phone number Pin
DanYELL9-Jul-09 10:00
DanYELL9-Jul-09 10:00 
AnswerRe: CEdit Phone number Pin
teejayem14-Jul-09 7:17
teejayem14-Jul-09 7:17 
QuestionDeclaring variables as 'new' in C++ CLR - Heap or GCHeap? Pin
Will58019-Jul-09 5:31
Will58019-Jul-09 5:31 
AnswerRe: Declaring variables as 'new' in C++ CLR - Heap or GCHeap? Pin
Mark Salsbery9-Jul-09 6:49
Mark Salsbery9-Jul-09 6:49 
QuestionCLR C++ Q. Does BYTE b[10] create a ref class System.Array? Pin
Will58019-Jul-09 3:15
Will58019-Jul-09 3:15 
AnswerRe: CLR C++ Q. Does BYTE b[10] create a ref class System.Array? Pin
Mark Salsbery9-Jul-09 6:50
Mark Salsbery9-Jul-09 6:50 
GeneralRe: CLR C++ Q. Does BYTE b[10] create a ref class System.Array? Pin
ant-damage2-Sep-09 1:04
ant-damage2-Sep-09 1:04 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.