|
LunaticFringe wrote: I take it there's some history here I'm unaware of.
Check MrM's previous posts, I have tried quite hard to teach him what development is about, but with little success. Perhaps someone else can engage with him sufficiently to get the message across.txtspeak is the realm of 9 year old children, not developers. Christian Graus
|
|
|
|
|
Richard's reply is dead on. This thread[^] is a particularly good example. He also periodically tries to troll for "exployees" for his "company". The theme is something like I'll glady pay you when the game makes big bucks as long as you do ALL the work today. You measure democracy by the freedom it gives its dissidents, not the freedom it gives its assimilated conformists.
|
|
|
|
|
Thanks for the link. A little comedy on an otherwise quiet Sunday afternoon. The guy can't use an 'if' statement, but...
'Richard maybe you shouldn't be that cheeky as I don't think you know how powerful and well respectedand I am. I have close contacts with the BBC and serveral companies who are interested in sponsorship and advertising opportunities within my 3D virtaul world.' - MrMcIntyre
L u n a t i c F r i n g e
|
|
|
|
|
Yes, it's pretty obvious he didn't even step though the offending code, although he knew exactly where it was, with the debugger and ask himself why nothing happens between putting up the message box and then exiting the program. Maybe he thought the message box would take care of it for him? But then, why put in your own exit call?
You kind of hate to discourage youth and enthusiasm but when it gets in the way of actually learning...You measure democracy by the freedom it gives its dissidents, not the freedom it gives its assimilated conformists.
|
|
|
|
|
Hello,
My main goal is to convert Matlab functions into .dll and then import that into a program called Metatrader. But my shorter goal is to actually be able to compile the .cpp made from Matlab, and I am unable to do so for some reason. Here are the details:
Although the functions I want to import are much more complex, for the sake of the problem, I've created 2 sample functions - AddTwo(x,y) and MultiplyTwo(x,y) in Matlab.
function output = AddTwo(x,y)
output = x + y;
function output = MultiplyTwo(x,y)
output = x * y;
Next, I compile them using mcc command (using Visual C++ 6.0 as C++ compiler).
mcc -W cpplib:libmatrix -T link:lib AddTwo MultiplyTwo
This got me several files, like the .cpp, .h, and .dll files. If I import the .dll file into Metatrader and try to use it now, it gives me 127 error (problem with .def/function names) or a critical error (crash when function names are corrected). So my goal here is to go inside the .cpp file and edit it to make it compatible with Metatrader and then compile it. The problem is that even when I don't edit it I can't seem to compile the basic file.
On the side, these are the requirements of the .dll file and exported functions to work properly in Metatrader:
Your DLL and the exported functions must fullfill the following requirements to be used from metatrader:
function name:
* not mangled
calling convention:
* stdcall
possible function arguments (when passed by value):
* 32bit integer
* double
* Pointer to nullterminated string
possible function arguments (when passed by reference):
* Pointer to array of
o 32 bit integer
o double
* no intergers by reference due to bug(?) in mql compiler
* no doubles by reference due to bug(?) in mql compiler
possible function return values:
* 32bit integer
* double
* Pointer to nullterminated string (contents will be copied immediately)
I am not completely familiar with these things (the top two I kind of understand).
So my primary goals are to:
1. Be able to compile the .cpp file in the first place
2. Make the .cpp file fulfill the above requirements for Metratrader.
Now, what I've done so far trying to compile the unedited .cpp file is include the necessary .lib files - mclmcr.lib mclmcrrt.lib - from Matlab's extern/lib/win32/microsoft folders. This took away many LINK2001 errors. But now I don't know what to do and when I try to build the .dll I get the following error message:
--------------------Configuration: libmatrix - Win32 Debug--------------------
Compiling...
libmatrix.cpp
Linking...
Creating library Debug/libmatrix.lib and object Debug/libmatrix.exp
libmatrix.obj : error LNK2001: unresolved external symbol ___MCC_libmatrix_component_data
LIBCD.lib(crt0.obj) : error LNK2001: unresolved external symbol _main
Debug/libmatrix.exe : fatal error LNK1120: 2 unresolved externals
Error executing link.exe.
libmatrix.exe - 3 error(s), 0 warning(s)
I am not very familiar with using Visual C++ 6.0
Also, because I can't attach files here, I will post the libmatrix.cpp and libmatrix.h code here. But you can generate these by making the Matlab functions and converting them via mcc.
libmatrix.cpp
#include <stdio.h>
#define EXPORTING_libmatrix 1
#include "libmatrix.h"
#ifdef __cplusplus
extern "C" {
#endif
extern mclComponentData __MCC_libmatrix_component_data;
#ifdef __cplusplus
}
#endif
static HMCRINSTANCE _mcr_inst = NULL;
#if defined( _MSC_VER) || defined(__BORLANDC__) || defined(__WATCOMC__) || defined(__LCC__)
#ifdef __LCC__
#undef EXTERN_C
#endif
#include <windows.h>
static char path_to_dll[_MAX_PATH];
BOOL WINAPI DllMain(HINSTANCE hInstance, DWORD dwReason, void *pv)
{
if (dwReason == DLL_PROCESS_ATTACH)
{
if (GetModuleFileName(hInstance, path_to_dll, _MAX_PATH) == 0)
return FALSE;
}
else if (dwReason == DLL_PROCESS_DETACH)
{
}
return TRUE;
}
#endif
#ifdef __cplusplus
extern "C" {
#endif
static int mclDefaultPrintHandler(const char *s)
{
return mclWrite(1 , s, sizeof(char)*strlen(s));
}
#ifdef __cplusplus
}
#endif
#ifdef __cplusplus
extern "C" {
#endif
static int mclDefaultErrorHandler(const char *s)
{
int written = 0;
size_t len = 0;
len = strlen(s);
written = mclWrite(2 , s, sizeof(char)*len);
if (len > 0 && s[ len-1 ] != '\n')
written += mclWrite(2 , "\n", sizeof(char));
return written;
}
#ifdef __cplusplus
}
#endif
#ifndef LIB_libmatrix_C_API
#define LIB_libmatrix_C_API /* No special import/export declaration */
#endif
LIB_libmatrix_C_API
bool MW_CALL_CONV libmatrixInitializeWithHandlers(
mclOutputHandlerFcn error_handler,
mclOutputHandlerFcn print_handler)
{
if (_mcr_inst != NULL)
return true;
if (!mclmcrInitialize())
return false;
if (!GetModuleFileName(GetModuleHandle("libmatrix"), path_to_dll, _MAX_PATH))
return false;
if (!mclInitializeComponentInstanceWithEmbeddedCTF(&_mcr_inst,
&__MCC_libmatrix_component_data,
true, NoObjectType, LibTarget,
error_handler, print_handler, 78041,
path_to_dll))
return false;
return true;
}
LIB_libmatrix_C_API
bool MW_CALL_CONV libmatrixInitialize(void)
{
return libmatrixInitializeWithHandlers(mclDefaultErrorHandler, mclDefaultPrintHandler);
}
LIB_libmatrix_C_API
void MW_CALL_CONV libmatrixTerminate(void)
{
if (_mcr_inst != NULL)
mclTerminateInstance(&_mcr_inst);
}
LIB_libmatrix_C_API
long MW_CALL_CONV libmatrixGetMcrID()
{
return mclGetID(_mcr_inst);
}
LIB_libmatrix_C_API
void MW_CALL_CONV libmatrixPrintStackTrace(void)
{
char** stackTrace;
int stackDepth = mclGetStackTrace(_mcr_inst, &stackTrace);
int i;
for(i=0; i<stackDepth; i++)
{
mclWrite(2 , stackTrace[i], sizeof(char)*strlen(stackTrace[i]));
mclWrite(2 , "\n", sizeof(char)*strlen("\n"));
}
mclFreeStackTrace(&stackTrace, stackDepth);
}
LIB_libmatrix_C_API
bool MW_CALL_CONV mlxAddTwo(int nlhs, mxArray *plhs[], int nrhs, mxArray *prhs[])
{
return mclFeval(_mcr_inst, "AddTwo", nlhs, plhs, nrhs, prhs);
}
LIB_libmatrix_C_API
bool MW_CALL_CONV mlxMultiplyTwo(int nlhs, mxArray *plhs[], int nrhs, mxArray *prhs[])
{
return mclFeval(_mcr_inst, "MultiplyTwo", nlhs, plhs, nrhs, prhs);
}
LIB_libmatrix_CPP_API
void MW_CALL_CONV AddTwo(int nargout, mwArray& output, const mwArray& x, const mwArray& y)
{
mclcppMlfFeval(_mcr_inst, "AddTwo", nargout, 1, 2, &output, &x, &y);
}
LIB_libmatrix_CPP_API
void MW_CALL_CONV MultiplyTwo(int nargout, mwArray& output, const mwArray& x, const
mwArray& y)
{
mclcppMlfFeval(_mcr_inst, "MultiplyTwo", nargout, 1, 2, &output, &x, &y);
}
libmatrix.h
#ifndef __libmatrix_h
#define __libmatrix_h 1
#if defined(__cplusplus) && !defined(mclmcrrt_h) && defined(__linux__)
# pragma implementation "mclmcrrt.h"
#endif
#include "mclmcrrt.h"
#include "mclcppclass.h"
#ifdef __cplusplus
extern "C" {
#endif
#if defined(__SUNPRO_CC)
#ifdef EXPORTING_libmatrix
#define PUBLIC_libmatrix_C_API __global
#else
#define PUBLIC_libmatrix_C_API /* No import statement needed. */
#endif
#define LIB_libmatrix_C_API PUBLIC_libmatrix_C_API
#elif defined(_HPUX_SOURCE)
#ifdef EXPORTING_libmatrix
#define PUBLIC_libmatrix_C_API __declspec(dllexport)
#else
#define PUBLIC_libmatrix_C_API __declspec(dllimport)
#endif
#define LIB_libmatrix_C_API PUBLIC_libmatrix_C_API
#else
#define LIB_libmatrix_C_API
#endif
#ifndef LIB_libmatrix_C_API
#define LIB_libmatrix_C_API /* No special import/export declaration */
#endif
extern LIB_libmatrix_C_API
bool MW_CALL_CONV libmatrixInitializeWithHandlers(
mclOutputHandlerFcn error_handler,
mclOutputHandlerFcn print_handler);
extern LIB_libmatrix_C_API
bool MW_CALL_CONV libmatrixInitialize(void);
extern LIB_libmatrix_C_API
void MW_CALL_CONV libmatrixTerminate(void);
extern LIB_libmatrix_C_API
void MW_CALL_CONV libmatrixPrintStackTrace(void);
extern LIB_libmatrix_C_API
bool MW_CALL_CONV mlxAddTwo(int nlhs, mxArray *plhs[], int nrhs, mxArray *prhs[]);
extern LIB_libmatrix_C_API
bool MW_CALL_CONV mlxMultiplyTwo(int nlhs, mxArray *plhs[], int nrhs, mxArray *prhs[]);
extern LIB_libmatrix_C_API
long MW_CALL_CONV libmatrixGetMcrID();
#ifdef __cplusplus
}
#endif
#ifdef __cplusplus
#if defined(_MSC_VER) || defined(__BORLANDC__)
#ifdef EXPORTING_libmatrix
#define PUBLIC_libmatrix_CPP_API __declspec(dllexport)
#else
#define PUBLIC_libmatrix_CPP_API __declspec(dllimport)
#endif
#define LIB_libmatrix_CPP_API PUBLIC_libmatrix_CPP_API
#else
#if !defined(LIB_libmatrix_CPP_API)
#if defined(LIB_libmatrix_C_API)
#define LIB_libmatrix_CPP_API LIB_libmatrix_C_API
#else
#define LIB_libmatrix_CPP_API /* empty! */
#endif
#endif
#endif
extern LIB_libmatrix_CPP_API void MW_CALL_CONV AddTwo(int nargout, mwArray& output, const mwArray& x, const mwArray& y);
extern LIB_libmatrix_CPP_API void MW_CALL_CONV MultiplyTwo(int nargout, mwArray& output, const mwArray& x, const mwArray& y);
#endif
#endif
I know this is a long message. I hope someone can help! Thanks! I've tried pretty much everywhere!
|
|
|
|
|
Your errors are from linker...
There are no lines like:
#pragma comment(lib, "neededLib.lib") Check your definition of Irrationality[ ^]
1 - Avicenna
5 - Hubbard
3 - Own definition
|
|
|
|
|
Hi,
But mbuild from Matlab is able to create the .dll file fine. Then why does this .cpp file not have the #pragma? And how can I tell which libs are needed?
Is that the only error?
|
|
|
|
|
You may find that you get some better answers on the MATLAB web site, someone else may have solved this already. The problem you have is with the output of your matlab generator, rather than with the .cpp files. txtspeak is the realm of 9 year old children, not developers. Christian Graus
|
|
|
|
|
0. Please start the VS wizard to create a DLL project
(now you product is an EXE - see the last output line)
and then fill it with your additional code.
1. Please start the "Find in files" tool (find in *.c; *.cpp; *.lib)
to find the variable __MCC_libmatrix_component_data in MATLABs dirs -
you could try to add the found *.cpp or *.lib in to your DLL project.
Good luck
PS. The answer for your why is:
MATLAB has the __MCC_libmatrix_component_data inside (not as an extern)Check your definition of Irrationality[ ^]
1 - Avicenna
5 - Hubbard
3 - Own definition
|
|
|
|
|
Long post. I think I read more questions in it than you actually asked.
I have no personal experience with MatLab or MetaTrader, so at some point here I might be indulging in a bit of speculation. (You do know about speculation, no? )
skyhr wrote: LIBCD.lib(crt0.obj) : error LNK2001: unresolved external symbol _main
The references to crt0.obj and unresolved external symbol _main sound to me like the build configuration is trying to pull in the start up code for a standalone program rather than the DLL that you are trying for. Are you sure that you have your project configured for a DLL and not an exe? Another possibility: I have seen comments that this can be caused by calling for _ATL_MIN_CRT in your project settings. I believe that for your purposes, you will not be using ATL at all, so check your project settings for that.
skyhr wrote: I've done ... is include the necessary .lib files - mclmcr.lib mclmcrrt.lib ...
--------------------Configuration: libmatrix - Win32 Debug--------------------
...
libmatrix.obj : error LNK2001: unresolved external symbol ___MCC_libmatrix_component_data
First a side note. There are several ways that you tell a linker what to include: entries in a project file, command line arguments, and embedded directives in a code module. The pragma mentioned by the earlier poster is the latter method. When you cleared up most of your unresolved externals by including a couple of libs, you probably did it via a project file. It works just fine that way too. The matlab build probably used the command line. So, the reason matlab could build successfully without the pragma directives was that it used a different method to tell the linker about the library. They are all legitimate approaches.
Now, I was going to say that this unresolved external just meant that you were missing another lib file. Then I looked closer and decided that I was wrong. Notice the libmatrix in the symbol which is your name, not matlab's. Also note the line extern mclComponentData __MCC_libmatrix_component_data; in you cpp file. This says that there is such a thing, but it is either being defined later or in a different file. Further, the matlab site states: Encrypts MATLAB code so that it cannot be viewed or modified. My current theory is that the matlab compiler is taking your code, mucking with it, and sticking it in another file. This one just contains the interface. You said, "This got me several files, like the .cpp, .h, and .dll files." Is there another file? Maybe even a .obj file? (but not, I think, plain libmatrix.obj)
Hopefully this will help you get a build. I think there will be issues dealing with the Metatrader interface, but that is the next step. I think it will also require more information.Please do not read this signature.
|
|
|
|
|
The snippets as follows:
CAboutDlg dlg;
dlg.DoModal();
Now,how to pass data to the modal dialog,for example modify the title of the modal dialog.Thx!I am not a genius, but shed more sweat!
|
|
|
|
|
Override OnInitDialog and change any values there. If you need the values to be set before instantiating the dialog then add class members and set their values when you first create the dialog object.txtspeak is the realm of 9 year old children, not developers. Christian Graus
|
|
|
|
|
You could extend the constructor of the dialog
to accept the passed parameter(s) by dialogs member(s).
As Richard said,
all visual things should be apllied at OnInitDialog() ,
as the m_hWnd is already valid,
for example:
if (m_cszPassedTitle.GetLength()) {
SetWindowText(m_cszPassedTitle);
} Check your definition of Irrationality[ ^]
1 - Avicenna
5 - Hubbard
3 - Own definition
|
|
|
|
|
The other alternative to the above suggestions, is that you define your own message, and use that to signal to your
child window that you've got some data for it.
I use the following code to pass an image to a child window.
IDC_COPYIMAGE is the message I defined. (#define IDC_COPYIMAGE 1010) There just needs to be an appropriate handler in the windowproc for the child dialog.
if (myWad.getLumpSize(myItem.iItem) == 4096)
{
flatData = (char*)myWad.loadResource(resNum, &resLen);
pal = (char*) myWad.loadResource(195, &resLen);
darkMap = (char*) myWad.loadResource(1, &resLen);
tmpImg = createImageFromFlat(flatData, pal, darkMap);
delete pal;
delete flatData;
delete darkMap;
SendMessage(imgChildHWND, IDC_COPYIMAGE, 0, (LPARAM)tmpImg);
DeleteObject(tmpImg);
}
|
|
|
|
|
I want to create a modeless dialog as main window. But I got error when calling function CreateDialog:
Unhandled exception at 0x7e424d76 in ModelessTest.exe: 0xC0000005: Access violation writing location 0x00000014.
This is my code:
BOOL CModelessTestApp::InitInstance()
{
CWinApp::InitInstance();
SetRegistryKey(_T("Local AppWizard-Generated Applications"));
CModelessTestDlg dlg;
m_pMainWnd = &dlg;
LPTSTR szAppName = MAKEINTRESOURCE(dlg.IDD);
MSG msg ;
WNDCLASS wndclass ;
memset(&wndclass, 0, sizeof(WNDCLASS));
wndclass.style = CS_HREDRAW | CS_VREDRAW;
wndclass.lpfnWndProc = ::DefWindowProc;
wndclass.cbWndExtra = DLGWINDOWEXTRA;
wndclass.hInstance = AfxGetInstanceHandle();
wndclass.hIcon = LoadIcon(IDR_MAINFRAME);
wndclass.hCursor = LoadCursor(IDC_ARROW);
wndclass.hbrBackground = (HBRUSH)(COLOR_BTNFACE + 1);
wndclass.lpszClassName = dlg.IDD_CLASS;
if (!AfxRegisterClass(&wndclass)) {
TRACE("Class Registration Failed\n");
MessageBox (NULL, TEXT ("This program requires Windows NT!"), szAppName, MB_ICONERROR);
return 0 ;
}
HWND hDlg = ::CreateDialog(GetModuleHandle(NULL), szAppName, NULL, NULL);
ShowWindow(hDlg, SW_SHOW);
while (GetMessage(&msg, NULL, 0, 0)) {
if (!IsDialogMessage(hDlg, &msg)) {
TranslateMessage(&msg) ;
DispatchMessage(&msg) ;
}
}
return FALSE;
}
The error is at this line:
HWND hDlg = ::CreateDialog(GetModuleHandle(NULL), szAppName, NULL, NULL);
But If I use the MFC way to create the modeless dialog, there is no error. For example, in above code, these codes:
HWND hDlg = ::CreateDialog(GetModuleHandle(NULL), szAppName, NULL, NULL);
ShowWindow(hDlg, SW_SHOW);
are replaced with:
dlg.Create(dlg.IDD);
dlg.ShowWindow(SW_SHOW);
HWND hDlg = dlg.m_hWnd;
it will manage to create the dialog.
Anyone know what's the cause?
Note: I'm using VC++ 2005
Thx in advance.modified on Saturday, March 6, 2010 5:13 AM
|
|
|
|
|
Your CreateDialog() call is missing some parameters; see here[^] for the description of what is required.txtspeak is the realm of 9 year old children, not developers. Christian Graus
|
|
|
|
|
Could you tell what's the missing parameter? I am totally clueless about this. I'm once thinking that I have to specify the DialogProcedure, but I saw the example from other resource (if using pure windows API way) that it doesn't need to specify the third and fourth parameter. Then I tried to provide the DialogProcedure and it still got error.
|
|
|
|
|
rudyono wrote: Could you tell what's the missing parameter?
The link I gave you clearly shows what parameters this function requires.
rudyono wrote: I am totally clueless about this.
I suggest you try something simpler; the code you posted above appears somewhat complicated. I am not sure what it is you are trying to achieve here or why you want to use a modeless dialog instead of a normal main window for your program.txtspeak is the realm of 9 year old children, not developers. Christian Graus
|
|
|
|
|
rudyono wrote: I want to create a modeless dialog as main window.
In what way are they different:
a modal dialog as main window and
a modeless dialog as main window ? Check your definition of Irrationality[ ^]
1 - Avicenna
5 - Hubbard
3 - Own definition
|
|
|
|
|
The distinction between modal and modeless dialogs is important and significant, but in your particular case of the main app window, I have to agree with Eugen Podsypalnikov that it seems to be a moot point.
I notice as well that you have written your own message loop and included it in App::InitInstance, bypassing the one provided as a part of MFC. I see no reason for you to be doing this.
I am puzzled by what you are trying to do here. It seems to me that you are writing an MFC app, but specifically bypassing MFC in it, instead nesting a win32 api application inside of it. This makes me nervous about how the various pieces of code in your app will interact.
Writing an MFC app is fine.
Writing a win32 app is fine.
I don't get what you are doing here. Perhaps you could try and clarify things for at least one of us? Please do not read this signature.
|
|
|
|
|
Here is the story, I want to make an MFC application with a splash screen. The problem is my app is a modal dialog and a modal dialog cannot startup as invisible, so that's why I was looking for modeless dialog as main window way. I was succeeded (to make modeless dialog as main window as said in my first post. It's just a curiousity that I replace the 2 line of MFC code to create a modeless dialog with win32 API code to do same thing, and it failed to create a modeless dialog. So I just want to know why the win32 API code is failed?
Btw, I already know how to solve my initial problem pertaining relationship between modal dialog and splash screen, so I had switched back to modal dialog.
|
|
|
|
|
Hi all,
i want to convert a CString value to DWORD. My problem is i am having hex value in my CString variable for ex.
CString str = 0x002C036D;
now i want to convert this value to DWORD.
How can i do this??????
Thanks in advance...
|
|
|
|
|
you can covert it to char * first,then use atoi.
Good Luck !
|
|
|
|
|
The statement
CString str = 0x002C036D; does not make much sense to me. Maybe you meant to say
CString str = _T("0x002C036D"); A simple function will do the conversion. You probably need to take a look at the function sscanf .
|
|
|
|
|
|