Click here to Skip to main content
15,896,154 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: Late Binding Concept Pin
pasztorpisti24-Sep-12 1:46
pasztorpisti24-Sep-12 1:46 
GeneralRe: Late Binding Concept Pin
Chris Meech24-Sep-12 2:19
Chris Meech24-Sep-12 2:19 
GeneralRe: Late Binding Concept Pin
pasztorpisti24-Sep-12 2:37
pasztorpisti24-Sep-12 2:37 
AnswerRe: Late Binding Concept Pin
Chuck O'Toole24-Sep-12 5:16
Chuck O'Toole24-Sep-12 5:16 
GeneralRe: Late Binding Concept Pin
pasztorpisti24-Sep-12 6:00
pasztorpisti24-Sep-12 6:00 
GeneralRe: Late Binding Concept Pin
pasztorpisti24-Sep-12 6:19
pasztorpisti24-Sep-12 6:19 
GeneralRe: Late Binding Concept Pin
Chuck O'Toole24-Sep-12 7:53
Chuck O'Toole24-Sep-12 7:53 
QuestionCallBack Function Pin
Smart Arab23-Sep-12 4:47
Smart Arab23-Sep-12 4:47 
Hi, have a good day
I am using Already built DLL , with callback function inside it :

After I execute this code my application freeze ( SomeCallback : read only once ) and freeze

I don't know what is wrong ?

DLL Define code ( DLL is open source ) :
C++
typedef int __stdcall cbtype (char *what, Number int1, Number int2, char *str);

extern "C" int __cdecl FreeArcExtract (cbtype *callback, ...);



My Code :
C#
#include <cstdlib>
#include <iostream>
#include "windows.h"

using namespace std;

typedef bool  (*cbtype)  (char *what, int, int, char *str);

bool SomeCallback( char *c1 , int i1 , int i2, char *c2)
{
     printf("%s\r\n" , c1);
     printf("%d\r\n" , i1);
     printf("%d\r\n" , i2);
     printf("%s\r\n" , c2);
     return true;
}

void ArcExtract ()
{  
	
	HINSTANCE GetProcDLL = LoadLibrary("unarc.dll");
    FARPROC GetProcessID = GetProcAddress(
HMODULE (GetProcDLL), "FreeArcExtract");

	typedef int (__cdecl * CallingFun)(cbtype, LPCTSTR , LPCTSTR, LPCTSTR , LPCTSTR,LPCTSTR , LPCTSTR,LPCTSTR , LPCTSTR,LPCTSTR , LPCTSTR);

    CallingFun FreeArcExtract;
    FreeArcExtract = CallingFun(GetProcessID);
	
	FreeArcExtract((cbtype)SomeCallback,
"l", "--", "d:\\test.arc", "", "", "", "", "", "", "");
    FreeLibrary(GetProcDLL);
}

int main(int argc, char *argv[])
{
    ArcExtract ();
    //system("pause");

    return EXIT_SUCCESS;
}


I think the error are in the call back function


I write the same code on C# and it's work like charming.

with same dll , and the same d:\test.arc

C# Code :
C#
class ArcArchive
        {
            public delegate bool unarcCallBack(string what, int param1, int param2, string text2);

            [DllImport("unarc.dll")]
            public static extern int FreeArcExtract(unarcCallBack callback, 
string cmd1, string cmd2, string cmd3, string cmd4, string cmd5, string cmd6, string cmd7, string cmd8, string cmd9, string cmd10);
        }

        static void Main(string[] args)
        {
            ArcArchive.unarcCallBack ArcCallBack = new ArcArchive.unarcCallBack(CallBackFunction);
            ArcArchive.FreeArcExtract(ArcCallBack,
 "l", "--", "d:\\test.arc", "", "", "", "", "", "", "");
        }

        static bool CallBackFunction(string what, int param1, int param2, string t2)
        {

            Console.WriteLine(what);
            Console.WriteLine(param1);
            Console.WriteLine(param2);
            Console.WriteLine(t2);
            return true;

        }



please is there is anyway to write callback function in c++ ? or is my c++ code had some logical errors.

Thank you
AnswerRe: CallBack Function Pin
Mohibur Rashid23-Sep-12 6:06
professionalMohibur Rashid23-Sep-12 6:06 
GeneralRe: CallBack Function Pin
Smart Arab24-Sep-12 1:39
Smart Arab24-Sep-12 1:39 
QuestionQuestion about MFC implementation Pin
Jian Jun Liu23-Sep-12 2:33
Jian Jun Liu23-Sep-12 2:33 
AnswerRe: Question about MFC implementation Pin
pasztorpisti23-Sep-12 3:20
pasztorpisti23-Sep-12 3:20 
GeneralRe: Question about MFC implementation Pin
Jian Jun Liu24-Sep-12 15:01
Jian Jun Liu24-Sep-12 15:01 
GeneralRe: Question about MFC implementation Pin
pasztorpisti24-Sep-12 15:23
pasztorpisti24-Sep-12 15:23 
GeneralRe: Question about MFC implementation Pin
Jian Jun Liu26-Sep-12 16:59
Jian Jun Liu26-Sep-12 16:59 
AnswerRe: Question about MFC implementation Pin
Chris Meech23-Sep-12 4:57
Chris Meech23-Sep-12 4:57 
GeneralRe: Question about MFC implementation Pin
pasztorpisti23-Sep-12 7:34
pasztorpisti23-Sep-12 7:34 
GeneralRe: Question about MFC implementation Pin
Chris Meech23-Sep-12 12:03
Chris Meech23-Sep-12 12:03 
Generalsource code Pin
pei0825010321-Sep-12 15:51
pei0825010321-Sep-12 15:51 
GeneralRe: source code Pin
Richard MacCutchan21-Sep-12 21:13
mveRichard MacCutchan21-Sep-12 21:13 
QuestionWhat makes C and C++ a "good" language? Pin
Brandon-X1200018-Sep-12 16:06
Brandon-X1200018-Sep-12 16:06 
AnswerRe: What makes C and C++ a "good" language? PinPopular
Richard Andrew x6418-Sep-12 16:20
professionalRichard Andrew x6418-Sep-12 16:20 
AnswerRe: What makes C and C++ a "good" language? Pin
Chris Losinger18-Sep-12 16:37
professionalChris Losinger18-Sep-12 16:37 
AnswerRe: What makes C and C++ a "good" language? Pin
Stephen Hewitt18-Sep-12 18:46
Stephen Hewitt18-Sep-12 18:46 
AnswerRe: What makes C and C++ a "good" language? PinPopular
CPallini18-Sep-12 21:27
mveCPallini18-Sep-12 21:27 

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.