|
Let me first state that I was not looking for discussion why to do this. I do get flustered when people change the subject of thread. But I mean no offense.
First – my projects are build to have parts reusable. My favorite place is Gallery.
This particular project is essentially user interface to ham radio.
The essential part is communication using serial port – hence a serial port DLL would be nice.
Next I need detailed trace of how this communication is accomplished – a log DLL is in order.
The program will eventually do Morse code , digital (packet) communication, etc.
My ultimate goal is slow scan television – both video and audio access to PC. .
As you can see, these piece parts do essentially same task – send data, make sure it gets there and then reverse the process.
So modularity is natural.
As far as naming conventions – I do not care much about that. For example – when you use MFC Property Sheets MFC names them for you ( 10 plus files for 10 pages) , not to intuitive but easy.
As far as using folders in VC 6.0 = absolutely out of question. Over the years I have been using VC++ I have lost the folders so many times , I do not care to count and waste my time.
Enough soap box.
Thanks for you input.
Vaclav
|
|
|
|
|
p1++ = map[((*p++ << 5) & 0x3) | ((*p >> 3) & 0x5)]; <-error, "p++" inoperative
p1++ = map[((*p++ << 7) & 0x5); <- ok, "p++"
but vc compiler do it like this
p1++ = map[((*p << 5) & 0x3) | ((*p >> 3) & 0x5)];
p++;
p1++ = map[((*p << 7) & 0x5);
p++;
why not
value = map[((*p << 5) & 0x3);
p++;
value |= ((*p >> 3) & 0x5)];
p1++ = value;
p1++ = map[((*p << 7) & 0x5);
p++;
how to fix it only use "++"modified on Sunday, March 7, 2010 6:33 AM
|
|
|
|
|
If you use a pointer (or indeed a value) in an expression, and the expression modifies that value (as you do above with p++ ) then the compiler will not guarantee that the new and old values are used in the order that you expect. This is due to compiler optimisation and is spelled out in the C++ language specification. In the line
p1++ = map[((*p++ << 5) & 0x3) | ((*p >> 3) & 0x5)];
if p contains 0x100 before this line is executed, then it will contain 0x101 afterwards. However there is no guarantee that it will contain 0x101 in the right half of the OR expression. You should rewrite your expressions to ensure no side effects.txtspeak is the realm of 9 year old children, not developers. Christian Graus
|
|
|
|
|
I'd code-review you back to kindergarden if I was presented code like that. Watched code never compiles.
|
|
|
|
|
So now im focusing on learning typedef, I read off functionX and made up my own piece of code:
#include "stdafx.h"
#include <string>
#include <conio.h>
#include <iostream>
using namespace std;
typedef string ThreeStrings[3];
int _tmain(int argc, _TCHAR* argv[])
{
ThreeStrings islands = { "Fiji" , "Caribbean" , "Bora Bora" };
for (int i=0 ; i < sizeof(islands) / sizeof(string); i++)
cout << "\n\t" << islands[i] << "\n" << endl;
_getch();
return 0;
}
So as you can see my typedef is declared Globally and you can also see that my alias is 'islands', I know I havent declared in my main or globally as 'int char or string' does that make it volatile or can only be used multiple times or changed in main?
Can I use 'islands' globally through other functions or only in main, and do I have to call it through other functions like
int function(typedef ThreeStrings islands)
{
.body..
}
|
|
|
|
|
I'm not exactly sure what you're asking. ThreeStrings can be used anywhere its definition is "visible": in this case anywhere in the file "Typedef.cpp" after "typedef string ThreeStrings[3]; ". Also note that's it's simply a typedef for an array of three std::string s so anywhere you see this:
ThreeStrings xxx;
it is equivalent to this:
std::string xxx[3];
islands is a local variable. It is mutable (its contents can be changed). Normally it is only visible within the _tmain function. It can be made available to functions called by _tmain (and functions called by functions called by _tmain , and so on) by passing a pointer or reference to it (or by making a pointer or reference to it accessible by some other means). For example:
void function(ThreeStrings &i)
{
i[0] = "I changed it!";
}
int _tmain(int argc, _TCHAR* argv[])
{
ThreeStrings islands = { "Fiji" , "Caribbean" , "Bora Bora" };
function(islands);
for (int i=0 ; i < sizeof(islands) / sizeof(string); i++)
cout << "\n\t" << islands[i] << "\n" << endl;
_getch();
return 0;
} Steve
|
|
|
|
|
Ok so if their equivalent what would be the purpose of using typedef, why not just use std:string? I need a bit more detail if that is ok, I tryed functionX and Cplusplus but still not seeing the differences.
|
|
|
|
|
A couple of reasons to use typedef is to make your code clearer to some poor human who has to read it.
If you're using a particular declaration a great number of places in your code, it MAY make your code clear if you make the intended use of those variables or funcitions obvious using typedefs.
Another is laziness. You often see typedefs where a particular declaration is very long and verbose, such as template classes and functions. It saves a lot of typing, retyping, and compiler errors to correct. And in the process, it may make your code more readable as well.You measure democracy by the freedom it gives its dissidents, not the freedom it gives its assimilated conformists.
|
|
|
|
|
Hi,
I am trying to format the contents of a RichEdit Control I would like to some how ensure the Begining of a new line
I realize I am dealing with pixels and not text characters and thus the length of a Line will vary if on line has more wide character pixels then the next
I plan to populate the RichEdit using streamin
I can the used the FindWordBreak method the determine where after populating the RichEdit The RichEdidt has decided to break the line
I can append the end of a line with say 5 blank characters
If a 1 line has more wide pixel character pixels the previous I can lets say remove 2 of the trailing blanks to force line a break to where I want
Though I am not quite sure how to remove charcters from the RichEdit Object
My question then is does what I am trying to do make sense
and if so is there a way to remove characters from the RichEdit before it is displayed
Thankx
|
|
|
|
|
ForNow wrote: to some how ensure the Begining of a new line
Please provide an example of what you are trying to do.
If you are streaming into the RichEdit Object, and you want to manipulate where the lines break, you will have to manipulate the stream before letting the RichEdit handle it.
|
|
|
|
|
Hi,
Please see this part of my code below for the message box that appears when the user presses the exit button, but if the user presses no on the message box the application still exit's. I have tried a good couple of times to fix it but it will not work. Please help.
case WM_KEYDOWN: <br />
if (wParam == VK_ESCAPE)<br />
MessageBox(NULL, L"Are you sure you want to exit?", L"My Project", MB_YESNO |MB_ICONQUESTION);<br />
DestroyWindow(hWnd);<br />
return 0;<br />
Thank you.Andrew McIntyre
|
|
|
|
|
You need to check the return value from MessageBox and execute DestroyWindow conditionally on the user response:
case WM_KEYDOWN:
if (wParam == VK_ESCAPE)
{
if (MessageBox(NULL, L"Are you sure you want to exit?", L"My Project", MB_YESNO |MB_ICONQUESTION) == IDYES)
DestroyWindow(hWnd);
}
return 0; L u n a t i c F r i n g e
|
|
|
|
|
Thank you so much, the code works fantastically. Andrew McIntyre
|
|
|
|
|
IMO, with proper formatting, you would have noticed that right away.
PS: please use PRE tags (not CODE tags) for showing code snippets here.
|
|
|
|
|
I knew it was something simple, but I need to spot these things better next time. Andrew McIntyre
|
|
|
|
|
Luc Pattyn wrote: IMO, with proper formatting, you would have noticed that right away.
PS: please use PRE tags (not CODE tags) for showing code snippets here.
But that's what his code actually looks like. You measure democracy by the freedom it gives its dissidents, not the freedom it gives its assimilated conformists.
|
|
|
|
|
I will remember to use PRE tags whenever I have snippets, sorry for using the wrong tags as I am not use to them yet. Andrew McIntyre
|
|
|
|
|
I don't know if you can help me with this but I want my application to check if the user has an internet connection and if they don't it will display a message box. How would I go about this? Andrew McIntyre
|
|
|
|
|
As you've been told countless times on this site, you need to get a few books, study the hell out of them and learn the basics, and then you can ask reasonable questions. Besides, I thought your employees were going to handle all the heavy lifting and you were just playing with this a little to see what slumming with the riff-raff felt like? You measure democracy by the freedom it gives its dissidents, not the freedom it gives its assimilated conformists.
|
|
|
|
|
I take it there's some history here I'm unaware of. L u n a t i c F r i n g e
|
|
|
|
|
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!
|
|
|
|
|