Frederick2 189 Posting Whiz

Good one Narue! Except I'd say SetConsoleCursorPosition() is cutting edge avant guard bleeding edge state of the art console mode coding for Windows!

Frederick2 189 Posting Whiz

I'm someone who uses old software all the time, and it continually amazes me the way most folks rail at old software. I fully realize I'm in the minority in terms of personally having no problems whatsoever with old software, and I've just had to face that, mostly keep my mouth shut (I don't enjoy being flammed anymore than anyone else does), and go on. I've accepted the fact that folks regularly throw away or recycle perfectly functioning computers that are only a couple years old, and disgard old perfectly functioning software and replace it with buggy bloated newer software. While I don't understand any of it, I think about it just about every day. The only possible theory I can come up with to explain all this (I think about it a lot) is its just the software related manifestation of consummerism whereby planned and hopefully accelerated obsolescence is required to maintain corporeate profits, keep programmers employed, so on and so forth.

Sometime in the late 1990s I used QuickBasic 4.5 (my Mother bought it for me for a birthday present around 1985 or so) to write data collector programs for the dual boot DOS / Windows CE data recorders my organization (a large forestry organization) uses to collect timber data. At this time in 2011 those programs are still being used and form the mainstay of out field data collection. I would guess that so far 300 million dollars worth of timber sale data have been collected …

WaltP commented: My experience exactly. +16
Frederick2 189 Posting Whiz

I need to ‘come clean’ Vivayan; I’m working on benchmarking various C++ compilers, programming languages, and algorithms, so just generating the last 4000 bytes of that series isn’t my goal. Also, I’m using this exercise to try to improve my knowledge of C++ and particularly String Class construction; String Classes are a particular interest of mine, since I’m an application programmer. My background is more in C and other programming languages than C++. Developing my String Class over the past several years has been a very good learning experience for me, and I have used it very successfully in my Windows CE work.

I’m working very hard on this right now, and if anyone is interested in commenting on what I’m doing or my code I’d appreciate it (maybe there are like minded folks out there!). Here is the PowerBASIC program I’m trying to implement and match as close as possible speed wise in either C or C++. It’ll do this 2MB buffer thing in 0.078 seconds (78 ticks) on my old laptop…

'1)Create a 2MB string of spaces; John Gleason’s original had 15 MB
'2)Change every 7th null to a "P"
'3)replace every "P" with a "PU" (hehehe)
'4)replace every null with an "8"
'5)Put in a carriage return & line feed every 90 characters
'DONE 0.078 secs!

#Compile Exe
#Dim All
Declare Function GetTickCount Lib "KERNEL32.DLL" Alias "GetTickCount" () As Dword

Function PBMain() As Long
  Local i, count7, currPos As Long
  Local s, s1 As String …
Frederick2 189 Posting Whiz

I find it hard to believe you are finding it hard to find links on ODBC. Here is a Wikipedial link...

http://en.wikipedia.org/wiki/Open_Database_Connectivity

I imagine wxWidgets must have some class wrappers on ODBC. If not you can use what I provided as a start. All those databases you listed in your first post are supported for sure. The beauty of ODBC is that you can use close to the same code for all. I say 'close to the same' because the standards allow for different levels of support. ODBC contains various functions that query the underlying proprietary database driver for functionalities supported. In that way your code can act appropriately to the context of its present environment.

Frederick2 189 Posting Whiz

I most definitely have a book recommendation for you and that is Charles Petzold's "Programming Windows" books. I most imagine all the book links at the top are about C++ specific issues. Creating GUI Windows programs is not a C++ specific issue as others have said.

Even if you choose some class framework to create GUI code, learning just a bit about the lower level Apis is a good idea in both the Windows world and the Linux world.

Ancient Dragon commented: Good book suggestion, I've used it myself and agree with you. +28
Frederick2 189 Posting Whiz

This is the "Data.dat" file i made from your data and saved as a text file in the same dir as the executable...

["link"] = "|cff1eff00|Hitem:7931:0:0:0:0:0:0:0:80|h[Mithril Coif]|h|r",},[45] = {["count"] = 1000,
["link"] = "|cff0070dd|Hitem:41165:0:0:0:0:0:0:0:80|h[Saronite Razorheads]|h|r",

Here is "Main.cpp" which is the main source file (not counting the String class in "Strings.h" and "Strings.cpp" to follow). Note I used CodeBlocks to create this. It is free software and very good. I actually prefer it to my Visual Studio 2008 Pro, which just puts you through a lot more hassle to start a project. Since I start a lot of small projects for testing purposes, that is a big issue for me. Anyway, if you are using Visual Studio you'll likely get piles of _CRT_SECURE_NO_WARNINGS. These can be turned off by pasting the above in the pre-processor definitions.

#include <tchar.h>
#include <stdio.h>
#include "Strings.h"

int main()
{
 char szBuffer[200];
 unsigned int iLn,iLn1;
 FILE* fp=NULL;
 String strLn;
 String* pLn1;
 String* pLn;

 fp=fopen("Data.dat","r");
 if(fp)
 {
    while(!feof(fp))
    {
       fgets(szBuffer,160,fp);
       strLn=szBuffer;
       iLn=strLn.ParseCount('|');
       printf("%d\t%s\n",iLn,szBuffer);
       pLn=new String[iLn];
       strLn.Parse(pLn,'|');
       for(unsigned int i=0; i<iLn; i++)
       {
           if(i==2)
           {
              iLn1=pLn[i].ParseCount(':');
              pLn1=new String[iLn1];
              pLn[i].Parse(pLn1,':');
              printf("\n\tThe Number You Are Looking For Is %s\n\n",pLn1[1].lpStr());
              delete [] pLn1;
           }
           printf("%u\t%s\n",i,pLn[i].lpStr());
       }
       delete [] pLn;
       printf("\n\n");
    }
    fclose(fp);
 }

 return 0;
}

/*
Output
==========================================================================================================

6       ["link"] = "|cff1eff00|Hitem:7931:0:0:0:0:0:0:0:80|h[Mithril Coif]|h|r",},[45] = {["count"] = 1000,

0       ["link"] = "
1       cff1eff00

        The Number You Are Looking For Is 7931

2       Hitem:7931:0:0:0:0:0:0:0:80
3       h[Mithril Coif]
4       h
5       r",},[45] = {["count"] = 1000,



6       ["link"] = …
jonsca commented: Great Effort! +2
Frederick2 189 Posting Whiz

Guess I should have figured lots of other folks are wondering the same thing and googled it. Found some good info here...

http://www.easysoft.com/developer/interfaces/odbc/64-bit.html

Ancient Dragon commented: excellent link +26
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

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

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

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

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.

Frederick2 189 Posting Whiz

I just recently posted some tutorials here...

http://www.jose.it-berater.org/smfforum/index.php?topic=3389.0

Lot of stuff having to do with pointers, message crackers, etc.

If you are into graphics at the Api level you should probably think about Charles Petzold's Programming Windows book. He is heavy into graphics. I can't really speak to other class framework wrappers on GDI or otherwise because I'm not into that.

zobadof commented: Thanks! +0
Frederick2 189 Posting Whiz

I'll tell you my opinion with the stress on OPINION. There is no easy way out. That's what everyone is looking for.

MFC will make it easier (3 months later). UMMM. This is getting confusing. UMMM. Maybe .NET will make it easier (6 months later and still 4 gigabytes of help docs to get through). UMMM. This is pretty confusing...

SomeObj.YetAnotherObj.ThenThisObj.ButDon'tForGetThisObj.ContainedInThisWorkSpace.AndNowAConrtainer....

But I'm willing to try anything but the basic Windows Api. Maybe Win32++...

Somebody please explain to me exactly how you can take a complex multitasking, multithreaded, multiwindowing system such as Windows, then overlay on top of that a complex object oriented layer as only C++ is capable of providing with its abstract base classes, inheritance chains, so on and so forth, and end up with something a beginner is supposed to understand. And the beginners are being told these other routes are easier than learning the basic Windows Api. That's the part that gets me.

Frederick2 189 Posting Whiz

Your declaration of destination only causes the compiler to allocate four bytes (32 bit OS) for the char* itself. In terms of memory at which it 'points', you need to allocate that with new, malloc, GlobalAlloc(), HeapAlloc(), whatever.

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

void strcpy2(const char* source, char* dest)
{	 
 while (*source != 0)
 {
   *dest = *source; 
   dest++;
   source++;
 }
 *dest = 0;
}


int main()
{	
 char* source = "Hello world";
 char* destination=NULL;
 
 destination=(char*)malloc(strlen(source)+1);
 if(destination)
 {
    strcpy2(source, destination);
    puts(source);
    puts(destination);
    free(destination); 
    system("pause");
 }   
 
 return 0;
}

The other alternative is to declare an arbitrarily sized character array to serve as a buffer into which you can copy the string. If you absolutely know what the upper possible bound of what you are copying is, then its possible to do that. For example, if you knew the character string you were copying couldn't be over 63 characters, you could do this...

char szStringBuffer[64];
if(strlen(source)<64)
   strcpy2(source, szStringBuffer);
else
   puts("Buffer Not Big Enough!!!");
Frederick2 189 Posting Whiz

There are a small number of us that write major Windows applications in various languages using almost exclusively the Win32 Api.

All programmers have their own biases, favorite way of doing things, etc. My favorite way of doing things most certainly doesn't suit everybody, but I've got to tell you, I find using the Win32Api directly for writting Windows applications to be optimal for me. I state this after having spent many years doing it all sorts of other ways, e.g., VB1 - 6, VB or C#.NET, MFC, etc.

What I found amusing about your post is your conception of writing programs against the Win32 Api as some kind of unusual and hard to imagine bizarre thing. It most certainly isn't.

What I think the reality is, is that a great many folks learn C++ now and start out writing console programs, then move on to writing GUI applications whose underlying foundation is the Win32 Api but this fact is all but hidden from them due to their passive acceptance of GUI libraries that completely hide the underlying Apis on which it is based. This process appears to me to be so far advanced at this point that many using GUI application frameworks aren't even aware that Windows doesn't require them. Period.

The other lamentable fact I have noticed in C++ and other languages is an over reliance on Windows Dialog Engine created windows. What inevitably seems to happen is that folks start trying to use …

Frederick2 189 Posting Whiz

This issue is the biggest problem I have in coding because it takes me a long time to develop the software, and the life expectancy of any specific configuration of OS and hardware is rather low. I'm certainly open to anything new that comes along, but I'm not hopeful.

Frederick2 189 Posting Whiz

Not really. The most useful and commonly used databases are known as 'relational databases' and the good thing about them is that they mostly follow the rules set down many years ago by all the big players in databases and those rules are ODBC. So, if you learn how to write a program that conncts to any particular one of these databases, then, chances are good that your program can switch to using another database with little or no modifications. For example, in my programming with Microsoft Access which I mentioned above, when I tested it with SQL Server, there were fairly minimal changes needing to be done to work wuth the latter. So what you need to do is get yourself some database to work with, learn a little SQL ( Structured Query Language ) , then see how you want to connect through C++ code if that's the way you want to go.

Frederick2 189 Posting Whiz

Hey Taphofyle!

You're into database programming with that. Unless you are a coding guru, I'd recommend not writing your own file structures, i.e., file access/retrieval, for something like that. If you haven't studied database programming yet, I'd recommend you do so. In C++ your choices are connecting with databases through higher level OOP front ends such as ADO (ActiveX Data Objects), or the lower level ODBC (Open DataBase Connectivity) route. I personally do all my database work through low level ODBC. I have some examples posted here...

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

Ancient Dragon commented: Good suggestion :) +36
Frederick2 189 Posting Whiz

I've been using first eVC++ 3 and now eVC++ 4 for about 10 years. They're certainly absolutely free.

There is very, very little difference coding for Win CE and coding Win32. As others have said very well, its good to have a good grasp of C & C++. Then you can code for anything.

Geez! I think the Sdks you have to download and install for each seperate piece of hardware are probably free too. At least for the devices I code for you can download the Sdks from their web site. However, if you want a real unit to test it on you'll need to beg, borrow, steal, or buy one!

Here about a month ago I had to finally break down and fork over $550 bucks for VS 2008 Pro. The units I'll be coding for in the future run Windows Moblie and apparently the free eMbedded VC++ 4.0 won't handle that.

I'll tell you what my issues are with this stuff. I really bust my butt trying to code excellent applications for the handheld data collection instruments we use for mission critical information in my organization, and the life expectancy of any particular piece of hardware, that is, not how long it will last but how long the manufacturer will continue to produce and support it, is really, really small. So what that means is that you need to be constantly ready to port your code to completely different hardware. Therein is the …

Salem commented: Nice post. +36
Frederick2 189 Posting Whiz

I have a general question about threads prompted by something strange I'm seeing in an application I developed involving ODBC access to Microsoft Access and SQL Server databases. Let me present the context of the problem first. I have been developing some tutorials on ODBC database access in two different languages, e.g., C++ and PowerBASIC. The programs are GUI apps in pure Sdk style. The way I created the demonstration programs is I created a main window with four buttons on it. When the 1st button is pressed the program scours the registry for SQL Driver information and opens up a scrollable output screen where all the registered ODBC drivers plus their attributes are listed.

Pressing the second button dumps a small sample Microsoft Excel worksheet to another output screen using ODBC.

Pressing the 3rd button creates a Microsoft Access database, creates a table within the database, inserts a few sample records in the database, then creates the output screen and displays diagnostic info and the records added.

The fourth button does the exact same thing as the third except with either Sql Server Express or MSDE.

The program is designed so that each button press creates a new output window, and if you repeatedly click a button, instead of creating a new database, records are simply added to the one created on the first button press. Each output window takes care of its own memory and cleanup.

In the various button press procedures I …

yonghc commented: Laudable effort at sharing very useful codes. However, the mouse movement codes are not working with CODEBLOK yet. +1
Frederick2 189 Posting Whiz

Thanks Salem. I'll try that. I'm new to the latest version of Visual Studio (just bought 2008 Pro), so I'm trying to find the best way to do things yet.

Frederick2 189 Posting Whiz

Hello Nihan1,

Below (if it all fits) is a C console program that uses direct ODBC function calls to create an Access Database in whatever directory you run the executable from, it then creates a table in the database, adds some data to it, then dumps the data to the console - providing output all the way. Certainly there are C++ classes to wrap all this as Ancient Dragon mentioned, but I simply do it as this code shows.

Also, an only slightly modified version of this program will do the same thing with SQL Server.

This particular program was compiled with Dev C++, but also works with VC++ 6. I imagine with Code::Blocks too. You need to add references to the ODBC libs.

/*  MkDB.c  To get this working in DevC++ create a new C project in its own directory
    such as MkDB, then copy this file into a C source code file and name it Main.c.
    Then go to the 'Project' on the main menu and select 'Project Options'.  A tabbed
    dialog box will open and select the 'Parameters' tab.  The 'Linker' list box at the
    far right has a button under it  which when clicked will display an 'Open File'
    dialog box where you will have to navigate to the 'lib' directory.  It is a multi-
    file selection dialog box and you will have to select the libodbc32.a and the
    libodbccp32.a libraries.
*/
#include "windows.h"
#include "stdio.h"
#include "stdlib.h"
#include "string.h"
#include "odbcinst.h" …
Ancient Dragon commented: Nice program :) +36
Frederick2 189 Posting Whiz

Well! The solution is obvious! If it wants a this pointer, then pass it one (to balance the stack)! This runs perfect in all three environments and no crashes!

#include <stdio.h> 

struct IX
{ 
 virtual void __stdcall Fx1()=0; 
 virtual void __stdcall Fx2()=0;
};  


struct IY
{ 
 virtual void __stdcall Fy1()=0; 
 virtual void __stdcall Fy2()=0;
};  


class CA : public IX, public IY
{ 
 virtual void __stdcall Fx1(){printf("Called Fx1()\n");}  
 virtual void __stdcall Fx2(){printf("Called Fx2()\n");}  
 virtual void __stdcall Fy1(){printf("Called Fy1()\n");}  
 virtual void __stdcall Fy2(){printf("Called Fy2()\n");}     
};

int main(void)
{ 
 void (__stdcall*pFn)(int);
 unsigned int* ptrVTbl=0;    
 unsigned int* VTable=0;      
 unsigned int i=0,j=0;        
 CA* pCA=0;                    
 
 printf("sizeof(CA) = %u\n\n", sizeof(CA)); 
 pCA=new CA; 
 ptrVTbl=(unsigned int*)pCA; 
 printf("i\t&ptrVTbl[]\t&VTable[]\tVTable[]\tpFn()\n"); 
 printf("====================================================================\n"); 
 for(i=0;i<2;i++) 
 {     
     VTable=(unsigned int*)ptrVTbl[i];     
     for(j=0;j<2;j++)     
     {
         printf
         (
          "%u\t%u\t\t%u\t\t%u\t\t",  //format specifiers
          i,                         //iterator
          &ptrVTbl[i],               //bytes 0-3 offset from pCA for i=0 and 4-7 when i=1 
          &VTable[j],                //address of function pointer held in VTable
          VTable[j]                  //value of function pointer in Vtable, i.e., address of function
         );
         pFn=(void(__stdcall*)(int))VTable[j]; //call function through function pointer
         pFn((int)pCA); //give it something to pop, even though its not used!                
     }
 } 
 printf("\n"); 
 getchar();
   
 return 0;
}
dougy83 commented: Clever! +2