this is from a more complicated dll, when I try to call a function in ??? that dll from vb, I can not see the output.
simple example
first:
make a Win32 Dynamic-Link Library with ms vc++ 6.0
sum int __stdcall sum(int a, int b)
{ int c;
c=a+b;
cout<<a<<" + " b<< " = "<<c<<endl;
return c;
}
after compling, the dll file named test.dll, in the c:\test.
second
in Visual Basic, declare the function:
Public Declare Function sum Lib "C:\test\test.dll" (ByVal a As Long, ByVal b As Long) As Long
then, add a button,
Private Sub Command1_Click()
Call MsgBox(sum(1, 2))
End Sub
I ran the vb program, Msgbox windows shows 3, the correct sum, but I can not see the output from cout, it should be like this:
1 + 2 = 3
I don't know how to see it, and where the cout result is!
anybody can tell me where and how to see the result?
thanks a lot in advance!
dll output problem - more details inside
Re:dll output problem - more details inside
somebody told me to think about the out flow destination, and sugges me not to use cout/printf, my question is that this is from a bigger scenario and I have to call another dll(algorithm) which use the printf to display information, so even I change my code to use message box to display information in C++, the algorithm dll still has a lot of information needed to be on the screen.
simply speaking, I need a Visual Basic interface, by which I can call a dll, the function called in dll will display some information by cout/printf, and I hope can find a way to show that information.
any help?
simply speaking, I need a Visual Basic interface, by which I can call a dll, the function called in dll will display some information by cout/printf, and I hope can find a way to show that information.
any help?
Re:dll output problem - more details inside
in order for printf/cout to work, the process needs to have the file descriptor for stdout opened, be it a console or a file.
a normal, windowed application does not own a console (observe how, if you launch it from a console, the prompt returns immediately while the application appears). it also does not open a file for that purpose.
i'm not sure whether you can obtain a console if you don't already own one. see msdn, there is a whole section on consoles and the console API.
you could also try to reopen stdout/stderr as files, see if that works.
i am very rusty on the details, though. haven't programmed windows for some time.
a normal, windowed application does not own a console (observe how, if you launch it from a console, the prompt returns immediately while the application appears). it also does not open a file for that purpose.
i'm not sure whether you can obtain a console if you don't already own one. see msdn, there is a whole section on consoles and the console API.
you could also try to reopen stdout/stderr as files, see if that works.
i am very rusty on the details, though. haven't programmed windows for some time.
Re:dll output problem - more details inside
Perhaps writing log files would be better (tail -f is really useful if you would be under Linux ...)
Re:dll output problem - more details inside
reopen really works!
thanks a lot
thanks a lot
zloba wrote: in order for printf/cout to work, the process needs to have the file descriptor for stdout opened, be it a console or a file.
a normal, windowed application does not own a console (observe how, if you launch it from a console, the prompt returns immediately while the application appears). it also does not open a file for that purpose.
i'm not sure whether you can obtain a console if you don't already own one. see msdn, there is a whole section on consoles and the console API.
you could also try to reopen stdout/stderr as files, see if that works.
i am very rusty on the details, though. haven't programmed windows for some time.
Re:dll output problem - more details inside
another question, without keyword "__stdcall", the dll compiled well and no warnings and errors, but can't be call by Visual Basic; after adding keyword "__stdcall", there is a linking error, it's like this, if my dll is named myapp.dll, the error message is:
myappbatch.obj: error LNK2001: unresolved external symbol _myapp
the strange thing is that the compiling process seems passed, and new dll generated and can be called by Visual Basic and runs smoothly.
I do use .def file in the following type:
LIBRARY myLib
EXPORTS
myDLLFuncName
any suggestion?
myappbatch.obj: error LNK2001: unresolved external symbol _myapp
the strange thing is that the compiling process seems passed, and new dll generated and can be called by Visual Basic and runs smoothly.
I do use .def file in the following type:
LIBRARY myLib
EXPORTS
myDLLFuncName
any suggestion?