Click here to Skip to main content
15,886,840 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
AnswerRe: Stuck at FILE_ATTRIBUTE_REPARSE_POINT attribute Pin
jschell25-Dec-13 8:03
jschell25-Dec-13 8:03 
QuestionLittle OT, but I am really puzzled by this. Pin
Vaclav_23-Dec-13 15:12
Vaclav_23-Dec-13 15:12 
AnswerRe: Little OT, but I am really puzzled by this. Pin
enhzflep23-Dec-13 21:02
enhzflep23-Dec-13 21:02 
AnswerRe: Little OT, but I am really puzzled by this. Pin
Richard MacCutchan23-Dec-13 22:09
mveRichard MacCutchan23-Dec-13 22:09 
QuestionRe: Little OT, but I am really puzzled by this. Pin
CPallini26-Dec-13 7:17
mveCPallini26-Dec-13 7:17 
AnswerRe: Little OT, but I am really puzzled by this. Pin
Vaclav_26-Dec-13 8:20
Vaclav_26-Dec-13 8:20 
GeneralRe: Little OT, but I am really puzzled by this. Pin
CPallini26-Dec-13 9:04
mveCPallini26-Dec-13 9:04 
QuestionCan't call a VB6 function from C Pin
Arm5523-Dec-13 5:42
Arm5523-Dec-13 5:42 
Hello everybody, I'm new in this forum. I don't know where to place this thread, because it's about VB6 and C, but I think the problem is in the C code so here I am. I'm working with C with no special focus, so the solution can be in C++ too Smile | :)

Well, this is the problem. I have a VB6 program that simply calls a function when the Command1 is pressed. This one:

VB
Public Function SampleSub(ByVal x As Integer, ByVal y As Integer) As Boolean
    MsgBox "Hello world!"
    SampleSub = True
End Function


I'm trying to call it from C like this:

C++
#include "main.h"

typedef BOOL (__stdcall *SampleSubPtr)(WORD, WORD);
static SampleSubPtr SampleSub;

DLL_EXPORT BOOL APIENTRY DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
{
    BOOL ret;

    if (fdwReason == DLL_PROCESS_ATTACH)
    {
            SampleSub = (SampleSubPtr)(0x00401B90);
            if (SampleSub == NULL)
                MessageBox(0, "SampleSub is NULL.", "M", 0);
            ret = SampleSub(5, 5);
    }

    return TRUE;
}


0x00401B90 is the pointer to the VB6 function. Then I place this DLL into the VB6 program memory space and the function is called. But it simply doesn't work. Debugging this with OllyDbg gives me this error when calling the function:

Access violation when reading [00000076]

I'm 100% sure that the function is at the address 0x00401B90. VB6 uses __stdcall and I use __stdcall from C. VB6 uses 16-bit integers and I use 16-bit integers (WORD) from C.

I can't solve this. Any ideas?

Thanks in advance! Smile | :)
QuestionRe: Can't call a VB6 function from C Pin
David Crow23-Dec-13 5:44
David Crow23-Dec-13 5:44 
AnswerRe: Can't call a VB6 function from C Pin
Arm5523-Dec-13 7:01
Arm5523-Dec-13 7:01 
GeneralRe: Can't call a VB6 function from C Pin
Richard Andrew x6423-Dec-13 9:13
professionalRichard Andrew x6423-Dec-13 9:13 
GeneralRe: Can't call a VB6 function from C Pin
Arm5523-Dec-13 10:08
Arm5523-Dec-13 10:08 
GeneralRe: Can't call a VB6 function from C Pin
Richard Andrew x6423-Dec-13 16:43
professionalRichard Andrew x6423-Dec-13 16:43 
GeneralRe: Can't call a VB6 function from C Pin
Arm5524-Dec-13 4:41
Arm5524-Dec-13 4:41 
GeneralRe: Can't call a VB6 function from C Pin
Richard Andrew x6424-Dec-13 6:51
professionalRichard Andrew x6424-Dec-13 6:51 
GeneralRe: Can't call a VB6 function from C Pin
Arm5524-Dec-13 7:11
Arm5524-Dec-13 7:11 
GeneralRe: Can't call a VB6 function from C Pin
Randor 24-Dec-13 18:12
professional Randor 24-Dec-13 18:12 
GeneralRe: Can't call a VB6 function from C Pin
Arm5525-Dec-13 9:25
Arm5525-Dec-13 9:25 
QuestionFrom where start? Pin
Le@rner20-Dec-13 21:15
Le@rner20-Dec-13 21:15 
AnswerRe: From where start? Pin
Richard MacCutchan20-Dec-13 22:05
mveRichard MacCutchan20-Dec-13 22:05 
GeneralRe: From where start? Pin
Le@rner20-Dec-13 22:34
Le@rner20-Dec-13 22:34 
GeneralRe: From where start? Pin
Richard MacCutchan20-Dec-13 22:40
mveRichard MacCutchan20-Dec-13 22:40 
GeneralRe: From where start? Pin
Le@rner20-Dec-13 22:44
Le@rner20-Dec-13 22:44 
GeneralRe: From where start? Pin
Richard MacCutchan20-Dec-13 23:12
mveRichard MacCutchan20-Dec-13 23:12 
GeneralRe: From where start? Pin
Le@rner20-Dec-13 23:58
Le@rner20-Dec-13 23:58 

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.