Frederick2 189 Posting Whiz
#include <stdio.h>
#include <string.h>

int main()
{
 char szBuffer[]="Hello, World!";

 puts("i       &szBuffer[i]    szBuffer[i]     szBuffer[i]     szBuffer + i");
 puts("=====================================================================");
 for(unsigned i=0; i<strlen(szBuffer); i++)
 {
     printf
     (
      "%u\t%u\t\t%u\t\t%c\t\t%s\n",
      i,
      (unsigned)&szBuffer[i],
      (unsigned)szBuffer[i],
      szBuffer[i],
      (szBuffer+i)
     );
 }

 return 0;
}

/*
i       &szBuffer[i]    szBuffer[i]     szBuffer[i]     szBuffer + i
=====================================================================
0       2293600         72              H               Hello, World!
1       2293601         101             e               ello, World!
2       2293602         108             l               llo, World!
3       2293603         108             l               lo, World!
4       2293604         111             o               o, World!
5       2293605         44              ,               , World!
6       2293606         32                               World!
7       2293607         87              W               World!
8       2293608         111             o               orld!
9       2293609         114             r               rld!
10      2293610         108             l               ld!
11      2293611         100             d               d!
12      2293612         33              !               !
*/

The last column above, i.e., szBuffer + i, is essentially what you were seeing with your example.

Frederick2 189 Posting Whiz
#include <stdio.h>
#include <string.h>

int main()
{
 char szBuffer[]="Hello, World!";

 puts("i       &szBuffer[i]    szBuffer[i]     szBuffer[i]");
 puts("===================================================");
 for(unsigned i=0; i<strlen(szBuffer); i++)
     printf("%u\t%u\t\t%u\t\t%c\n",i,(unsigned)&szBuffer[i],(unsigned)szBuffer[i],szBuffer[i]);

 return 0;
}

/*
i       &szBuffer[i]    szBuffer[i]     szBuffer[i]
===================================================
0       2293600         72              H
1       2293601         101             e
2       2293602         108             l
3       2293603         108             l
4       2293604         111             o
5       2293605         44              ,
6       2293606         32
7       2293607         87              W
8       2293608         111             o
9       2293609         114             r
10      2293610         108             l
11      2293611         100             d
12      2293612         33              !

Process returned 0 (0x0)   execution time : 0.015 s
Press any key to continue.
*/
Frederick2 189 Posting Whiz

When you specify this to output...

&say[0]

it tells cout to start outputing text from the address of say[0] until it hits a null - hence you get 'Hello'.


When you specify this to output...

&say[1]

it tells cout to start outputing text from the address of say[1] until it hits a null - hence you get 'ello'.

etc.

Frederick2 189 Posting Whiz

I have VS 2008 Pro but tend to use CodeBlocks for C++. Like all Microsoft software, VS has a very 'heavy' and 'slow' feel to it, i.e., massive gigabytes in installation, lots of hourglasses, slow to react, etc. I tend to use older equipment than most, so perhaps its not so bad with the very latest top end stuff. In my opinion Dev-Cpp is OK to start with. If you get serious about programming though, you'll tend to move on.

I think the download for Dev-Cpp is around 10MB. For CodeBlocks its around a hundred MB. Last summer I bought Visual Studio 2008 Pro and when I did the install I told it to install the works, including SQL Server 2005 Express, which was on the DVDs that came with it. The 'works' added about 18 gigabytes to my harddrive. Unbelievable for an old DOS hacker like me!

Frederick2 189 Posting Whiz

Some time ago I discovered that with both Microsoft Access and SQL Server the operating system, i.e., Windows, doesn't like databases anywhere at all in \Documents And Settings\...

It might work if you put the .mdb file somewhere else.

Frederick2 189 Posting Whiz

This is my first VB.NET post as I'm mainly a C/C++ and PowerBASIC developer. I'm trying to figure out how to pass a struct like so as a function parameter to/from a C/C++ or PowerBASIC dll using PInvoke of course in VB.NET. The struct in C looks like this...

struct MAXTransItem   //whatever...
{
 int     iItemNumber;                  //4 bytes
 char    szItemDescription[36];  //36 bytes
 double  dblCost;                       //8 bytes
};

This is just test code to see how to do it. I included an asciz null terminated char string buffer in the struct just because I knew that would be the most difficult. As you can see, that buffer is 36 bytes, and the whole struct would have a fixed memory footprint of 48 bytes.

Here is the whole dll code which just has one test function that I wish to access from VB.NET...

#include <string.h>

struct MAXTransItem   //whatever...
{
 int     iItemNumber;
 char    szItemDescription[36];
 double  dblCost;
};

extern "C" __declspec(dllexport) int __stdcall ProcessTrans(int, MAXTransItem&);


int __stdcall ProcessTrans(int iQuantity, MAXTransItem& mti)
{
 mti.iItemNumber=37;
 strcpy(mti.szItemDescription,"Genuine Ash Axe Handles");
 mti.dblCost=iQuantity*6.95;

 return true;
}

If you are not familiar with C++ the 2nd parameter is a reference parameter, i.e.,

MAXTransItem&

meaning the address of an allocated MAXTransItem struct must be passed in. I've been working for quite some time at this and am pretty well stuck. However, just today I found a reference to something which might work in Francesco Balena's book "Programming Microsoft Visual Basic.NET" published by Microsoft Press around 2002 or …

Frederick2 189 Posting Whiz

I think Narue's idea is really good. I'd learn both. Old C books and tutorials in C are easy to find and inexpensive. Start 1 chapter at a time in each and you'll soon find that one reinforces the other.

Frederick2 189 Posting Whiz

Because today your luck is running good! All kidding aside, it just so happens that that address is still within your address space, so it isn't crashing. Add a few more lines of code and do it and your luck will likely run out! Doing that sort of thing will eventually lead to memory corruption, and believe me, those are the very, very, very worst kinds of problems to encounter. One time I lost three solid weeks due to something like that. What generally happens is that bizarre problems are encountered at some point later in the program due to corruption of your data segmentor something like that.

tux4life commented: Excellent :) +6
Frederick2 189 Posting Whiz

I just put together an actual pair of C++ projects using your struct description and function signature and have it working. To load the dll you need to go into your project settings and link to the export library created by the dll creation process (that is, if you want to avoid LoadLibrary() / GetProcAddress()). Anyway, I named the dll 'CppDll.dll' and the host project 'dllHost.exe'. Here is the code for CppDll.dll...

//dllMain.cpp
/*
  Project CppDll  -- Compile as Dll


*/
#include <string.h>

struct MAXTransItem   //whatever...
{
 int     iItemNumber;
 char    szItemDescription[36];
 double  dblCost;
};

extern "C" __declspec(dllexport) int __stdcall ProcessTrans(int, MAXTransItem&);


int __stdcall ProcessTrans(int iQuantity, MAXTransItem& mti)
{
 mti.iItemNumber=37;
 strcpy(mti.szItemDescription,"Genuine Ash Axe Handles");
 mti.dblCost=iQuantity*6.95;

 return true;
}

And here is the code for the host app that loads the dll. The output follows directly after...

/*
  Project -- dllHost

  Main.cpp  In whatever C++ development environment you are using, you must
  link this executable with the CppDll.dll export library which contains the
  symbols exported from the dll.  Generally, there is some sort of option
  under Project Properties >> Build Options to set paths to export libraries.
  With Microsoft compilers these have an extension of .lib.  With GNU compilers
  the extension is *.a.  With Dev-Cpp or CodeBlocks, if the .a file is in the
  same directory as the host executable, specify the full path to the export
  library rather than a relative path.  The relative path will probably only
  work if the export library is in the \lib folder of …
Frederick2 189 Posting Whiz

Just occurred to me you'll probably need a LoadLibrary("PathToDll") call there too. Of course, in basic dialects that's included in the declare. The dllimport statement should make unnecessary a GetProcAddress() call.

Frederick2 189 Posting Whiz

This would be my guess...

#include <stdio.h>

struct MAXTransItem   //you need to define this...
{
 .....
 .....
 .....

};


__declspec(dllimport) int __stdcall ProcessTrans(int, MAXTransItem&);  


int main(void)
{
 MAXTransItem mti;
 int hObject;
 int iReturn;

 hObject = ????;  //fill in
 iReturn=ProcessTrans(hObject,XTrans);
 printf("iReturn = %d\n", iReturn);
 getchar();

 return 0;
}

...and the dll itself would need to be somewhere in the dll search path, such as the directiory from which the exe is executing.

Note that by appending the '&' symbol (C/C++ address of operator) to MAXTransItem, i.e., MAXTransItem&, you are stating that the address of the struct is being passed to the ProcessTrans() function, and this corresponds to BASIC pass by reference. Such a construct requires C++ compilation and will throw a compile error if C copilation is used. For C you would declare MAXTransItem* instead.

Frederick2 189 Posting Whiz

This is exactly what I can't find.

Perhaps you could point me to a how-to guide?

Don't know if this is what you are looking for, but I've written quite a few tutorials on issues relating to inter-operating between C/C++ and PowerBASIC here...

http://www.jose.it-berater.org/smfforum/index.php?board=380.0

Starting in around Program Examples 11 through 19 I give quite a few examples of calling dlls created in PowerBASIC and loading them in C++ and vice-versa; also parameter passing issues, etc. Some of it would relate to VB.NET I expect. I cover LoadLibrary() and GetProcAddress() there.

If you would post a function and any structs necessary here, I'd take a look at it tomorrow some time.

Frederick2 189 Posting Whiz

Well, I'm glad to hear you are making progress. However, just for your information I don't believe its necessary to use LoadLibrary() and GetProcAddress() to interact with the dll in C/C++ or most other languages. Just using proper function declares should be enough.

Frederick2 189 Posting Whiz

I expect you should be able to call the functions in the dll from vb.net. As mentioned by the other helpful poster, you will need some kind of header file from the dll to see what the exported functions look like. Having seen that, you should be able to generate vb declares. I'm not that terribly familiar with .NET (I don't like it although in the past I studied it a lot), but I call C functions from my programming language of choice (PowerBASIC) all the time. The main issue is translating variable types and calling conventions. For example, all basic languages pass variables by reference, whereas C family languages pass parameters by value. Once you iron out such problems it works very well to do such mixed language programming.

Do you have any idea what some of the function prototypes are?

Frederick2 189 Posting Whiz

How any commercial compiler manufacturer implements the C++ keyword 'new' is likely proprietary information, I expect. GlobalAlloc is of course unique to Win32. Its a function callable from any language capable of calling external functions. I use it a lot in PowerBASIC. I also use it in C and C++. So I wouldn't say the issue is unique to any language wheter C family or not. Of course you realize GlobalAlloc() isn't portable whereas new is - at least in the C++ world.

Yes, like Salem said, the differences between basic memory allocation functions (there are a lot of them in Win32) and the 'new' C++ operator is that 'new' does things very specific to the inner workings and logic of the C++ language relating to the operations of classes in terms of constructors and destructors, whereas basic memory allocation functions just give you a consequitive array of bytes.

Frederick2 189 Posting Whiz

You wouldn't have to spend one cent beyond what you already have to develop Win32 graphical user interface applications using the Windows Api, and if for some reason you find that too tiresome (after you've learned it proper, that is), the knowledge you've gained would be put to good use in adopting a class framework such as MFC. There are no easy ways out. No pain, no gain.

Frederick2 189 Posting Whiz

And your definition of "interface" is???

Frederick2 189 Posting Whiz

Hello I got a little problem with winapi programming I can edut dialogs graphically with resource editor but is there any way to edit mainform in similar way? Writing on iPod so there may be typos

No.

Frederick2 189 Posting Whiz

We already have the main source code; all that would be needed would be the h and rc file. I'd give a shot at compiling it if I had those. However, I'm wondering if some setting isn't messed up in the project file.

Frederick2 189 Posting Whiz

I simply failed to note you were using UNICODE and the TCHAR.h macros, so here is a TCHAR version with pre-processor definitions to quiet warnings. For the above program to run in VC9 Express you would need to set the char set to 'Not Set'.

//Project Properties >> Configuration Properties >> General >> "Use Unicode Character Set"
#include <windows.h>  //Paste In Pre-Processor Definitions...
#include <tchar.h>    //;_CRT_SECURE_NO_WARNINGS;_CRT_NON_CONFORMING_SWPRINTFS
#include <stdio.h>

typedef struct    WindowsEventArguments               //Package Window Procedure Parameters into structure
{
 HWND             hWnd;                               //Handle of Window
 WPARAM           wParam;                             //Window Parameter
 LPARAM           lParam;                             //Long Parameter
 HINSTANCE        hIns;                               //Instance Handle (Resolves To Process Address)
}WndEventArgs, *lpWndEventArgs;


long fnWndProc_OnCreate(lpWndEventArgs Wea)           //Called One Time During Window Creatiion
{                                                     //This corresponds to Form_Load() in Visual Basic.
 Wea->hIns=((LPCREATESTRUCT)Wea->lParam)->hInstance;  //lParam is pointer to CREATESTRUCT in WM_CREATE
 return 0;                                            //Handles WM_CREATE message.
}


long fnWndProc_OnPaint(lpWndEventArgs Wea)
{
 TCHAR szBuffer[64],szText[8],szCharSet[16];
 PAINTSTRUCT ps;
 TEXTMETRIC tm;
 FILE* fp=NULL;
 HDC hDC;

 fp=_tfopen(_T("Output.txt"),_T("w"));
 _ftprintf(fp,_T("Entering fnWndProc_OnPaint()\n"));
 hDC=BeginPaint(Wea->hWnd,&ps);
 SetBkMode(hDC,TRANSPARENT);
 GetTextMetrics(hDC,&tm);
 _tcscpy(szBuffer,_T("tm.tmHeight = "));
 _stprintf(szText,_T("%u"),(unsigned int)tm.tmHeight);
 _tcscat(szBuffer,szText);
 TextOut(hDC,0,0,szBuffer,_tcslen(szBuffer));
 _ftprintf(fp,_T("  tm.tmHeight = %u\n"),(unsigned int)tm.tmHeight);
 _stprintf(szText,_T("%u"),(unsigned int)tm.tmAveCharWidth);
 _tcscpy(szBuffer,_T("tm.tmAveCharWidth = "));
 _tcscat(szBuffer,szText);
 TextOut(hDC,0,20,szBuffer,_tcslen(szBuffer));
 _ftprintf(fp,_T("  tm.tmAveCharWidth = %u\n"),(unsigned int)tm.tmAveCharWidth);
 _tcscpy(szBuffer,_T("tm.tmCharSet = "));
 _stprintf(szText,_T("%u"),tm.tmCharSet);
 _tcscat(szBuffer,szText);
 TextOut(hDC,0,40,szBuffer,_tcslen(szBuffer));
 _ftprintf(fp,_T("  tm.tmCharSet = %u\n"),(unsigned int)tm.tmCharSet);
 switch(tm.tmCharSet)
 {
  case ANSI_CHARSET:
    _tcscpy(szCharSet,_T("ANSI_CHARSET"));
    break;
  case DEFAULT_CHARSET:
    _tcscpy(szCharSet,_T("DEFAULT_CHARSET"));
    break;
  case SYMBOL_CHARSET:
    _tcscpy(szCharSet,_T("SYMBOL_CHARSET"));
    break;
  case SHIFTJIS_CHARSET:
    _tcscpy(szCharSet,_T("SHIFTJIS_CHARSET"));
    break;
  case HANGEUL_CHARSET:
    _tcscpy(szCharSet,_T("HANGEUL_CHARSET"));
    break;
  case CHINESEBIG5_CHARSET:
    _tcscpy(szCharSet,_T("CHINESEBIG5_CHARSET"));
    break;
  case OEM_CHARSET:
    _tcscpy(szCharSet,_T("OEM_CHARSET"));
    break;
  case JOHAB_CHARSET:
    _tcscpy(szCharSet,_T("JOHAB_CHARSET"));
    break;
  case HEBREW_CHARSET:
    _tcscpy(szCharSet,_T("HEBREW_CHARSET"));
    break;
  case ARABIC_CHARSET:
    _tcscpy(szCharSet,_T("ARABIC_CHARSET"));
    break;
  case GREEK_CHARSET:
    _tcscpy(szCharSet,_T("GREEK_CHARSET"));
    break;
  case TURKISH_CHARSET:
    _tcscpy(szCharSet,_T("TURKISH_CHARSET"));
    break;
  case THAI_CHARSET:
    _tcscpy(szCharSet,_T("THAI_CHARSET"));
    break;
  case EASTEUROPE_CHARSET:
    _tcscpy(szCharSet,_T("EASTEUROPE_CHARSET"));
    break;
  case RUSSIAN_CHARSET:
    _tcscpy(szCharSet,_T("RUSSIAN_CHARSET"));
    break; …
Frederick2 189 Posting Whiz

At least on my browsers there is a page 2 to that original post of yours, and the code I was referring to is the 1st and only post in page 2...

http://www.daniweb.com/forums/thread245406-2.html

Frederick2 189 Posting Whiz

Frederick, i did NOT abandon that post, i tried all you guys told me but to no avail, and since nobody had replied to that post again i decided to bring it up again. I tried EVERYTHING you guys told me to dobut it was still giving me chinese. The code in the tutorial compiled to give English output, so thatwas why i posted this post.

Not so Tkud. Here is the link to your previous post....

http://www.daniweb.com/forums/thread245406.html

If you check that out you'll see an entire program I wrote for you to compile and run which implemented Clinton Portis's suggestion to you to extract the character set equate out of the TEXTMETRIC struct so we could use that as a starting point to see why you were getting the strange results you are reporting. It took about an hour of my time to prepare that program for you to run, and I did it partially as a learning experience for you because if you are attempting to learn Sdk style C or C++ programming you need early on to understand Window Device Contexts and the TEXTMETRIC struct.

Since you appear to be someone who just abandons posts where people expend considerable effort to help you, and start new ones asking the same questions, I'm not inclined to help any further. In any case, I do wish you a Merry Christmas!

Frederick2 189 Posting Whiz

Hey everyone, since nobody has decided to assist me in my problems, ...

If I recall, a number of people tried to assist you in your problems, and I even provided a program for you to run so we could see what character set you were using. Correct me if I'm wrong, but you simply abandoned your post, and are now starting another one, with the same problems apparently, i.e., Chinese output.

Frederick2 189 Posting Whiz

In terms of files, with the exception of the unicode situation, there doesn't seem to be much difference between desktop Windows and Windows CE. I don't do iostream, but I'd be very surprised if it didn't work identically on CE to its behavior on desktop Windows. In terms of anything in stdio or the Windows Api itself, I've never encountered any differences except some fairly well know things such as lack of a default path, unicode, etc. What differences you'll find on CE compared to desktop Windows will be on other aspects than the file system.

Frederick2 189 Posting Whiz

I spend about 50% to 60% of my time doing Windows CE and I just use the stdio.h functions for text output and I usually do the Api functions (CreateFile, SetFilePointer, etc.) for binary access. Here's an example of opening my DEBUG output file in one of my CE programs...

FILE* fp;

#if defined(MYDEBUG)
 fp=_tfopen(_T("\\C_DRIVE\\Silvah\\Output.txt"),_T("w"));
 _ftprintf(fp,_T("Output.txt Opened During fnWndProc_OnCreate()\n"));
 _ftprintf(fp,_T("MYDEBUG Is Defined!\n"));
 #endif
Frederick2 189 Posting Whiz

Rajesh just gave you excellent advice.

Yes i actually came across that today, but its done in C. Is there one that is done in C++?

You may not know this, but MFC is just an OOP wrapper on the C Win Api. No matter how much you don't want to face that, its the simple truth.

Frederick2 189 Posting Whiz

Its because of stuff like that that I gave up on iostream years and years ago. If you're working in Windows and you've got serious work to do, you need the Win32 Console functions in conjunction with stdio. Just my opinion, of course. And I fully realize I'm a blasphemer. By the way, I didn't look at all your code, but you don't need stdio or cstdio if you aren't using puts(), printf(), or anything like that. I needed it cuz I used puts instead of the more laborious WriteConsole().

Frederick2 189 Posting Whiz

its not portable, but for windows works good...

#include <windows.h>
#include <stdio.h>

void cls(HANDLE hStdOutput)
{
 COORD coordScreen = {0,0};
 DWORD cCharsWritten;
 CONSOLE_SCREEN_BUFFER_INFO csbi;
 DWORD dwConSize;
 
 GetConsoleScreenBufferInfo(hStdOutput, &csbi);
 dwConSize = csbi.dwSize.X * csbi.dwSize.Y;
 FillConsoleOutputCharacter(hStdOutput,(TCHAR)' ',dwConSize,coordScreen,&cCharsWritten);
 GetConsoleScreenBufferInfo(hStdOutput,&csbi);
 FillConsoleOutputAttribute(hStdOutput,csbi.wAttributes,dwConSize, coordScreen,&cCharsWritten);
 SetConsoleCursorPosition(hStdOutput,coordScreen);
}

int main(void)
{
 HANDLE hStdOutput;

 puts("Hello, World!"); 
 hStdOutput=GetStdHandle(STD_OUTPUT_HANDLE);
 puts("     /npress any key to continue.....");
 getchar();
 cls(hStdOutput);
 puts("Screen Cleared!");
 getchar(); 

 return 0;
}
Frederick2 189 Posting Whiz

Anyhow.. Thanks allot for your activity here on DaniWeb; I really appreciate it allot that you spent some time of your day to help me.

Well, no problem. I like to help if I can. Right now I have some time on my hands because I'm at home recovering from a neck operation. Anyway, I wanted to see if I could get by without using resource scripts so when you were having difficulty and couldn't get one to work I decided to explore the matter a little. However, I do think you ought to try to solve your resource script problem, because even if you decide to go the route I showed, you'll still need to understand and use them if for no other reason than everybody else uses them a lot.

On that note last night I spent about an hour experimenting with command line compiling using Dev-Cpp and I got it to work. Post back here if you want to give it a try and I'll lead you through it. Might be possible to compile that recalcitrant program that way

Also, I've written quite a bit of beginning Api tutorials here...

http://www.jose.it-berater.org/smfforum/index.php?board=380.0

I'll probably post some new stuff there shortly. The GUI stuff starts around ProgEx37 I think.

Frederick2 189 Posting Whiz

can you help me do a program using array in c++.
1. accepts 10 input numbers and output its sum and average.
2.accepts 10 input numbers and arrange it from highest to lowest.
3. accepts 10 input numbers will output the highest number and lowest number.

thank you.

The rules here at DaniWeb are that you have to at least put in some of your own effort and try. So why don't you start it and when you get stuck ask a question?

Frederick2 189 Posting Whiz

Here is a whole program implementing Clinton Portis's suggestion of getting the char set out of the TEXTMETRIC struct. Just run the program and post the results here of what was on the screen. Also, it prints the output to a text file in whatever dir you run it from (Output.txt))...

Main.cpp
#include <windows.h>
#include <stdio.h>

typedef struct    WindowsEventArguments               //Package Window Procedure Parameters into structure
{
 HWND             hWnd;                               //Handle of Window
 WPARAM           wParam;                             //Window Parameter
 LPARAM           lParam;                             //Long Parameter
 HINSTANCE        hIns;                               //Instance Handle (Resolves To Process Address)
}WndEventArgs, *lpWndEventArgs;


long fnWndProc_OnCreate(lpWndEventArgs Wea)           //Called One Time During Window Creatiion
{                                                     //This corresponds to Form_Load() in Visual Basic.
 Wea->hIns=((LPCREATESTRUCT)Wea->lParam)->hInstance;  //lParam is pointer to CREATESTRUCT in WM_CREATE
 return 0;                                            //Handles WM_CREATE message.
}


long fnWndProc_OnPaint(lpWndEventArgs Wea)
{
 char szBuffer[64],szText[8],szCharSet[16];
 PAINTSTRUCT ps;
 TEXTMETRIC tm;
 FILE* fp=NULL;
 HDC hDC;

 fp=fopen("Output.txt","w");
 fprintf(fp,"Entering fnWndProc_OnPaint()\n");
 hDC=BeginPaint(Wea->hWnd,&ps);
 SetBkMode(hDC,TRANSPARENT);
 GetTextMetrics(hDC,&tm);
 strcpy(szBuffer,"tm.tmHeight = ");
 sprintf(szText,"%u",(unsigned int)tm.tmHeight);
 strcat(szBuffer,szText);
 TextOut(hDC,0,0,szBuffer,strlen(szBuffer));
 fprintf(fp,"  tm.tmHeight = %u\n",(unsigned int)tm.tmHeight);
 sprintf(szText,"%u",(unsigned int)tm.tmAveCharWidth);
 strcpy(szBuffer,"tm.tmAveCharWidth = ");
 strcat(szBuffer,szText);
 TextOut(hDC,0,20,szBuffer,strlen(szBuffer));
 fprintf(fp,"  tm.tmAveCharWidth = %u\n",(unsigned int)tm.tmAveCharWidth);
 strcpy(szBuffer,"tm.tmCharSet = ");
 sprintf(szText,"%u",tm.tmCharSet);
 strcat(szBuffer,szText);
 TextOut(hDC,0,40,szBuffer,strlen(szBuffer));
 fprintf(fp,"  tm.tmCharSet = %u\n",(unsigned int)tm.tmCharSet);
 switch(tm.tmCharSet)
 {
  case ANSI_CHARSET:
    strcpy(szCharSet,"ANSI_CHARSET");
    break;
  case DEFAULT_CHARSET:
    strcpy(szCharSet,"DEFAULT_CHARSET");
    break;
  case SYMBOL_CHARSET:
    strcpy(szCharSet,"SYMBOL_CHARSET");
    break;
  case SHIFTJIS_CHARSET:
    strcpy(szCharSet,"SHIFTJIS_CHARSET");
    break;
  case HANGEUL_CHARSET:
    strcpy(szCharSet,"HANGEUL_CHARSET");
    break;
  case CHINESEBIG5_CHARSET:
    strcpy(szCharSet,"CHINESEBIG5_CHARSET");
    break;
  case OEM_CHARSET:
    strcpy(szCharSet,"OEM_CHARSET");
    break;
  case JOHAB_CHARSET:
    strcpy(szCharSet,"JOHAB_CHARSET");
    break;
  case HEBREW_CHARSET:
    strcpy(szCharSet,"HEBREW_CHARSET");
    break;
  case ARABIC_CHARSET:
    strcpy(szCharSet,"ARABIC_CHARSET");
    break;
  case GREEK_CHARSET:
    strcpy(szCharSet,"GREEK_CHARSET");
    break;
  case TURKISH_CHARSET:
    strcpy(szCharSet,"TURKISH_CHARSET");
    break;
  case THAI_CHARSET:
    strcpy(szCharSet,"THAI_CHARSET");
    break;
  case EASTEUROPE_CHARSET:
    strcpy(szCharSet,"EASTEUROPE_CHARSET");
    break;
  case RUSSIAN_CHARSET:
    strcpy(szCharSet,"RUSSIAN_CHARSET");
    break;
  default:
    strcpy(szCharSet,"Unknown");
    break;
 }
 TextOut(hDC,0,60,szCharSet,strlen(szCharSet));
 fprintf(fp,"  tm.tmCharSet = %s\n",szCharSet);
 EndPaint(Wea->hWnd,&ps);
 fprintf(fp,"Leaving fnWndProc_OnPaint()\n"); …
Frederick2 189 Posting Whiz

Been butchering up your code pretty bad Cody! Don't think you'll recognize it anymore. Added some Open File Dialog stuff on the File Menu, and added two versions of 'Message Crackers'. The 2nd program has a little include file...

1st

//Main.cpp
#include <windows.h>              //Program creates menu and dialog box programatically, i.e.,
#include <commdlg.h>              //without resource script file ( *.rc ).  Also shows simplest
#include <stdio.h>                //way of breaking the Window Procedure into message handling
#define IDC_STATIC          -1    //routines.  Some functionality of the File Open Dialog Box
#define ID_FILE_OPEN      1500    //from the Common Dialog Box Library Comdlg32.dll is shown.
#define ID_FILE_SAVE      1505    //Finally, printing output to a Debug output file is shown
#define ID_FILE_EXIT      1510    //where the file is opened in the WM_CREATE handler and finaly
#define ID_OPTIONS        1600    //appended to and closed in the WM_CLOSE handler.  Program
#define IDD_ABOUT         1700    //compiled on CodeBlocks to 9728 bytes.  Win32 programs do
#define IDD_DIALOGABOUT   1700    //not become bloatware.
#define IDD_GROUP         1705
#define IDD_OK            1710
#define IDD_CANCEL        1715


long __stdcall DlgProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
 switch(msg)    //This is the Window Procedure for the 'Dialog' Window Class Registered
 {              //down in WndProc_OnCreate().  It is a normal Window Procedure - not a
    case WM_CREATE:  //Dialog Box Proceure As used by the Windows Dialog Engine.
      EnableWindow(GetParent(hwnd),FALSE);  //To make the popup dialog/window modal
      return 0;
    case WM_COMMAND:
      switch(LOWORD(wParam))
      {
         case IDD_OK:
           MessageBox(hwnd,"You Clicked The OK Button!","OK Button Click!",MB_OK);
           SendMessage(hwnd,WM_CLOSE,0,0);
           break;
         case IDD_CANCEL:
           MessageBox(hwnd,"You Clicked The Cancel Button!","Cancel Button Click!",MB_OK);
           SendMessage(hwnd,WM_CLOSE,0,0);
           break;
      } …
Frederick2 189 Posting Whiz

The background color of the dialog window needs to be changed to COLOR_BTNSHADOW in the WNDCLASSEX struct...

#include <windows.h>
#define IDC_STATIC          -1
#define ID_FILE_OPEN      1500
#define ID_FILE_SAVE      1505
#define ID_FILE_EXIT      1510
#define ID_OPTIONS        1600
#define IDD_ABOUT         1700
#define IDD_DIALOGABOUT   1700
#define IDD_GROUP         1705
#define IDD_OK            1710
#define IDD_CANCEL        1715


long __stdcall DlgProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
 switch(msg)
 {
    case WM_CREATE:
      EnableWindow(GetParent(hwnd),FALSE);  //To make the popup dialog/window modal
      return 0;
    case WM_COMMAND:
      switch(LOWORD(wParam))
      {
         case IDD_OK:
           MessageBox(hwnd,"You Clicked The OK Button!","OK Button Click!",MB_OK);
           SendMessage(hwnd,WM_CLOSE,0,0);
           break;
         case IDD_CANCEL:
           MessageBox(hwnd,"You Clicked The Cancel Button!","Cancel Button Click!",MB_OK);
           SendMessage(hwnd,WM_CLOSE,0,0);
           break;
      }
      return 0;
    case WM_CLOSE:
      EnableWindow(GetParent(hwnd),TRUE);   //To re-enable main window
      DestroyWindow(hwnd);
      return 0;
    case WM_DESTROY:
      PostQuitMessage(0);
      return 0;
 }

 return DefWindowProc(hwnd, msg, wParam, lParam);
}


long __stdcall WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
 HINSTANCE hIns;

 switch(msg)
 {
    case WM_CREATE:
    {
      char szClassName[]="Dialog";
      HMENU hMenu, hSubMenu;
      WNDCLASSEX wc;

      hIns=((LPCREATESTRUCT)lParam)->hInstance;
      hMenu = CreateMenu();
      hSubMenu = CreatePopupMenu();
      AppendMenu(hSubMenu,  MF_STRING,            ID_FILE_OPEN,   "&Open");
      AppendMenu(hSubMenu,  MF_STRING,            ID_FILE_SAVE,   "&Save");
      AppendMenu(hSubMenu,  MF_SEPARATOR,         0,              0      );
      AppendMenu(hSubMenu,  MF_STRING,            ID_FILE_EXIT,   "E&xit");
      AppendMenu(hMenu,     MF_STRING | MF_POPUP, (UINT)hSubMenu, "&File");
      hSubMenu = CreatePopupMenu();
      AppendMenu(hSubMenu,  MF_STRING,            ID_OPTIONS,     "Explorer");
      AppendMenu(hMenu,     MF_STRING | MF_POPUP, (UINT)hSubMenu, "&Options");
      hSubMenu = CreatePopupMenu();
      AppendMenu(hSubMenu,  MF_STRING,            IDD_ABOUT,      "&About");
      AppendMenu(hMenu,     MF_STRING | MF_POPUP, (UINT)hSubMenu, "&Help" );
      SetMenu(hwnd, hMenu);

      //Register Window Class For Dialog Box
      wc.lpszClassName=szClassName,               wc.lpfnWndProc=DlgProc;
      wc.cbSize=sizeof(wc),                       wc.style=CS_HREDRAW | CS_VREDRAW;
      wc.cbClsExtra=0,                            wc.cbWndExtra=0;
      wc.hInstance=hIns,                          wc.hCursor=LoadCursor(NULL, IDC_ARROW);
      wc.hbrBackground=(HBRUSH)COLOR_BTNSHADOW,   wc.lpszMenuName=NULL;
      wc.hIcon=0;                                 wc.hIconSm=0;
      RegisterClassEx(&wc);

      return 0;
    }
    case WM_COMMAND:
      switch(LOWORD(wParam))
      {
         case ID_FILE_OPEN:
         {
           MessageBox(hwnd,"You Want To Open A File!","File Open!",MB_OK);
           return 0; …
Frederick2 189 Posting Whiz

Just thought I'd make a comment on the technical nature of what I did there. Its kind of fundamental. I completely removed the Windows Dialog Engine from the picture. The Windows Dialog Engine was created as kind of a wrapper on the basic RegesterClass() and CreateWindow() functionality within Windows. The intent was to simplify things for simple windows that are a little bit more complicated than Message Boxes, but not requiring the full functionality of custom made/designed Window Classes.

What I did was create a regular Window Class for the Dialog with the typical RegisterClassEx(), CreateWindow() sequence, and therefore I have an ordinary Window Procedure in the program to service the Window - not a Dialog Procedure which uses somewhat different messages. What I did was use the class styles typical of Dialog Boxes to accomplish this. Also note the EnableWindow() function was used to disable the main program window while the Dialog Box was active. This is typical of how modal dialog boxes work. They won't allow you to interact with other Windows until you dismiss them.

Frederick2 189 Posting Whiz

Hi Cody!

I'm really glad to hear it worked for you! I put some time into it because I've been thinking about eliminating resource scripts from my code to the extent possible; simply because I don't like them for some reason. I can't say I've ever had problems with them to the extent that you seemed to be having though.

One thought did occur to me though that I hadn't mentioned, and that was the issue of where you installed Dev-C++ to? I remember from years ago over at the Bloodshed Software Forum for Dev-C++ that they highly recommended that it be installed to C:\Dev-Cpp rather than to the more likely place of C:\Program Files\Dev-Cpp. Folks who installed it to file paths with spaces in them had the sorts of problems you were having, if I remember correctly. So I always followed their advice, even though I don't like to have my root C drive cluttered up with lots of directories.

Aren't the background colors messed up for you on the Dialog? I worked on the program in Win 2000, and posted it from that work. Then I tried it on XP and the labels were a bit messed up. I was going to work on it today. I've seen the problem before.

I'm just like you when it comes to working through computer or math stuff sequentially. The problem would have driven me nuts too! Take care.

Fred

Frederick2 189 Posting Whiz

Just discovered there is a background color problem in the dialog. It didn't show up in Win 2000 which I developed the program on. Saw it in XP. I'll see if I can fix it tomorrow.

Frederick2 189 Posting Whiz

I reworked your code Cody to do without the resource script. Now there is only one file - Main.cpp. I did make quite a few changes; you should be able to recognize it as your program though; and this should work. Hope it helps.

#include <windows.h>
#define IDC_STATIC          -1
#define ID_FILE_OPEN      1500
#define ID_FILE_SAVE      1505
#define ID_FILE_EXIT      1510
#define ID_OPTIONS        1600
#define IDD_ABOUT         1700
#define IDD_DIALOGABOUT   1700
#define IDD_GROUP         1705
#define IDD_OK            1710
#define IDD_CANCEL        1715


long __stdcall DlgProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
 switch(msg)
 {
    case WM_CREATE:
      EnableWindow(GetParent(hwnd),FALSE);  //To make the popup dialog modal
      return 0;
    case WM_COMMAND:
      switch(LOWORD(wParam))
      {
         case IDD_OK:
           MessageBox(hwnd,"You Clicked The OK Button!","OK Button Click!",MB_OK);
           SendMessage(hwnd,WM_CLOSE,0,0);
           break;
         case IDD_CANCEL:
           MessageBox(hwnd,"You Clicked The Cancel Button!","Cancel Button Click!",MB_OK);
           SendMessage(hwnd,WM_CLOSE,0,0);
           break;
      }
      return 0;
    case WM_CLOSE:
      EnableWindow(GetParent(hwnd),TRUE);   //To re-enable main window
      DestroyWindow(hwnd);
      return 0;
    case WM_DESTROY:
      PostQuitMessage(0);
      return 0;
 }

 return DefWindowProc(hwnd, msg, wParam, lParam);
}


long __stdcall WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
 HINSTANCE hIns;

 switch(msg)
 {
    case WM_CREATE:
    {
      char szClassName[]="Dialog";
      HMENU hMenu, hSubMenu;
      WNDCLASSEX wc;

      hIns=((LPCREATESTRUCT)lParam)->hInstance;
      hMenu = CreateMenu();
      hSubMenu = CreatePopupMenu();
      AppendMenu(hSubMenu,  MF_STRING,            ID_FILE_OPEN,   "&Open");
      AppendMenu(hSubMenu,  MF_STRING,            ID_FILE_SAVE,   "&Save");
      AppendMenu(hSubMenu,  MF_SEPARATOR,         0,              0      );
      AppendMenu(hSubMenu,  MF_STRING,            ID_FILE_EXIT,   "E&xit");
      AppendMenu(hMenu,     MF_STRING | MF_POPUP, (UINT)hSubMenu, "&File");
      hSubMenu = CreatePopupMenu();
      AppendMenu(hSubMenu,  MF_STRING,            ID_OPTIONS,     "Explorer");
      AppendMenu(hMenu,     MF_STRING | MF_POPUP, (UINT)hSubMenu, "&Options");
      hSubMenu = CreatePopupMenu();
      AppendMenu(hSubMenu,  MF_STRING,            IDD_ABOUT,      "&About");
      AppendMenu(hMenu,     MF_STRING | MF_POPUP, (UINT)hSubMenu, "&Help" );
      SetMenu(hwnd, hMenu);

      //Register Window Class For Dialog Box
      wc.lpszClassName=szClassName,             wc.lpfnWndProc=DlgProc;
      wc.cbSize=sizeof(wc),                     wc.style=CS_HREDRAW | CS_VREDRAW;
      wc.cbClsExtra=0,                          wc.cbWndExtra=0; …
Frederick2 189 Posting Whiz

I really like CodeBlocks with Visual Studio 2008 coming in a close second.

I'm with Narue on the class frameworks...

>2. What is your favorite GUI library
I equally dislike all of the ones I've tried.

...except that I think I hate MFC worst of all.

For Windows GUI programming I do standard Sdk with special message cracker routines I learned from Douglas Boling and his Windows CE books.

I compile as C++ but except for all the C Standard Library stuff I like I don't use class frameworks. I can't tolerate bloated programs.

I like to use classes for 'business objects'; not as wrappers around Win Api functionality.

Frederick2 189 Posting Whiz

I didn't knew the question was confusing. However some geniuses have decoded it correctly. Here I go again. Suppose I want to use bass.dll which have functions written in C, is there special thing i need to include or just give it a go?

Thanks for suggestions and link. I really learn here at DW

#include "bass.inc"

make sure bass.dll is somewhere in your dll search path. The same directory as your exe would work ok.

Frederick2 189 Posting Whiz

I'm inclined to think Cody might have a point about there being something wrong either with his Dev-Cpp install or something of that sort. He is continually having problems getting his programs to compile if they have resource scripts in them. And these same exact files are compiling with no problem for many of us here who try them- even when we use the Dev-C++ IDE.

For these reasons I'd be a bit surprised if a separate resource editor would make a difference. After all, all they do is auto-generate hopefully valid resource scripts, and the ones Cody already has ARE already valid resource scripts.

I've seen lots of anomolous behavior with the Dev-C++ setup already - especially regarding resource scripts.

Does anyone know the exact command line switches for compiling Cody's program from the command line using the gcc compiler installed with Dev-C++? I do command line compiling a pretty lot with MS compilers, and with gcc under Linux, but I've never done it with Windows gcc programs. If Cody would try that it might give a hint as to what his problems are.

Frederick2 189 Posting Whiz

I see alot of libraries written in C and I like C++ OOP way.
How can I use a given C library functions in C++?

I don't understand your question. All you need to do is include the header file and perhaps link with the library if its something unusual that isn't loaded by default. After all, C++ includes most of C.

For the most part, you can take any basic Win32 Sdk template type program usually associated with C style programming and rebuild the project in whatever development environment you are using as a C++ project; i.e., with .cpp extension instead of .c; and you automatically have the capability to do whatever OOP stuff you wish.

Essentially, that's how I program myself. A good deal of C++ I simply don't like; I have no use for it; I don't use it now; and have no intention of ever using it. I'm speaking most particularly of GUI class frameworks. However, there is a good bit of C++ that I do like so that's the part I use.

Perhaps an eclectic style, but it works for me. That's why your question confuses me. I must be misunderstanding your question because you surely know that.

Frederick2 189 Posting Whiz

Hi Cody!

I just tried the code posted by cikara21 and it worked perfectly including showing the 'About' dialog box. Somehow when I copied the code a few html tags showed up after the case about and I had to remove those. I used my Dev-C++ setup - 4.9.9.2 or something like that. Not sure if that's the newest or not. Is there a 5?

Dev-C++ is OK except the codetips infuriate me they are so intrusive. Maybe try CodeBlocks. I like that a lot. I also have VS2008 Pro but it cost me about $550. Like anything having to do with .NET its clunky and slow. It does produce generally small executables though. I believe CodeBlocks is only about a 20MB download. I'd guess that's doable from a dial up or otherwise slow connection.

Frederick2 189 Posting Whiz

I'll take a shot at it later when I have time Cody.

It seems to me you are letting yourself get overly hung up on these resource compiler/dialog issues. I'd move on to other stuff. Personally, I dislike everything to do with dialogs. I make very minimal use of them in my programs. There isn't hardly anything in Win32 programming that can't be done some other way than by using resource scripts and .rc files.

Frederick2 189 Posting Whiz

The code seems to have all the functionality within it for opening files. Have you tried opening a file that doesn't contain Chinese?

Frederick2 189 Posting Whiz

How create win32 application in Microsoft Visual Studio 2008 ??

I do not want to select " Empty project "

"Empty Project" is good. That's how I start all my VS projects. Of course, you have to know what to do next...

Frederick2 189 Posting Whiz

yaaa gotta make variables, then use ifs and loops is ther anythn else ya gotta know?

Frederick2 189 Posting Whiz

I only skimmed your question, but it sounded like:
http://parashift.com/c++-faq-lite/templates.html#faq-35.12

[edit]Short fix?

//Main.cpp
#include <stdio.h>
#include <string.h>
#include "CClient.h"
#include "TArray.cpp"

Thanks Dave! I just skimmed that doc, but it does look like my problem. Will work on it today.

Frederick2 189 Posting Whiz
/* I'm stuck!  Here is what I consider to be a perfectly running program that uses
   an array ( TArray ) template to hold arrays of objects.  Its just about your
   classic text book example.  Its pretty well stripped down to nothing to 
   illustrate my problem.  I simply don't know how to break it out into .cpp and 
   .h implementation and header files.  Been trying all day.  The output of this 
   program which does work follows.  It just uses a real simple class object as an
   example of something to contain, i.e., class CClient with a char* first name, a 
   char Sex, i.e., 'm', 'f', and an int age.  Its a 16 byte class.

   You can see with my template TArray class I didn't inline the members preparatory
   to seperating it out into TArray.cpp and TArray.h.  However, when I attempt to
   break my CClient and TArray objects into seperate implementation and header files
   I simply can't get it to link.  Not a compile error mind you, a link error!

   Anyway, here is the working program, and after this I'll provide the one that
   doesn't work with seperate files, i.e.,...

   
   CClient.h,  CClient.cpp
   TArray.h,   TArray.cpp
   Main.cpp

   In that order.  Please, can someone tell me what I'm doing wrong here?  I'm lost,
   demoralized, humiliated, and mystified.  Did I mention unhappy?

*/

#include <stdio.h>
#include <string.h>

class CClient
{
 public:
 CClient(){printf("CClient Uninitialized Constructor Called!\n");}
 ~CClient(){printf("CClient Destructor Called!\n");}

 void setclient(char* szName, char cSex, int iAge)
 {
  strcpy(m_szName,szName);
  m_Sex=cSex;
  m_Age=iAge;
 }

 void display(void)
 {
  printf("%s\t%c\t%d\n", …
Frederick2 189 Posting Whiz

Sometimes Dev-C++ 'sticks' and fails to save and utilize changes when you edit something. I oftentimes do a 'Clean' from the compile menu which deletes the existing binaries so it forces the IDE to generate new ones.

By all means you should include all the files in your project through the IDE's project functionality. It makes no sense not to do so.

Personally, I don't care for debuggers much. I usually open an output text file/trace file and print my debugging info, i.e., variables to that. In other words,

#include <stdio.h>

int main(void)
{
 FILE* fp=NULL;
 int iNum=5;

 fp=fopen("Output.txt","w");
 if(fp)
 {
    fprintf(fp,"Entering main()\n");
    fprintf(fp,"  iNum=%d\n",iNum);
    fprintf(fp,"Leaving main()\n");
    fclose(fp);
 }
 getchar();

 return 0;
}

//Output
//========================
//Entering main()
//  iNum=5
//Leaving main()

The most absolutely maddening thing about Dev-C++ is the horrible, horrible intrusiveness/buggyness of the d#$^& codetips! Just yesterday I became so exasperated with it I closed a project out and re-set it up with CodeBlocks. Many times the blasted thing is so bad that I have to close out the whole IDE and restart it to get a codetip to close! They even remain on the desktop!

Frederick2 189 Posting Whiz

A Copy Constructor has to completely generate a new Person object with the Person object passed as a parameter. Apparently one of the members of this Person object is a pointer to a struct/class that probably looks something like this...

class Date
{
 public:
 void set_year(short year);
 void set_month(short month);
 void set_day(short day)
 etc...
};

The newly created Person object can't use the memory allocations for the existing object passed as a parameter because if this later object gets destroyed/deleted/goes out of scope, the the new object will have bogus memory and will cause a crash. So every dynamically allocated member of the parameter class (the Person& parameter) will have to be duplicated by a memory allocation for the yet to be created object. That's what the 'new' is about. Then you'll have a completely independent object from the one passed in. So yes, you've answered your own question. It needs a new date memory block, otherwise, its sharing the other's, and won't be independent of it. Hope this helps.