Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

You mean interns actually get paid in $$$??? I thought all you got was college credit for your work.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Assuming the computer has the language fonts installed, yes. You might have to write the program in UNICODE and use wfprintf(), which is the unicode version of printf().

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

I think the explanation in this thread will solve that problem.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

You should never use gets() anyway because it could cause buffer overflow errors. Use fgets() instead.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

When you get a first entry-level programming job you will most likely not be writing all new code yourself, but instead you will be modifying and debugging existing code (program maintenance). The only new code you might write is to make product enhancements to existing products. No one is going to sit you down at a computer and expect you to write an entirely new program all by yourself.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Don't worry -- everyone has that problem from time-to-time. It frequently takes a lot of time and studying to figure out how another programmer wrote a program. Been there, and done that.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

See line 62. iret instruction returns control from an interrupt handler. On MS-DOS interrupt handlers are common to process hardware and software interrupts.

The program actually begins at the label named Start on line 64. It initializes a timer interrupt handler then jumps somewhere (line 82).

These are not really threads as we know them in MS-Windows and *nix. Nor will you be able to run that assembly code under MS-Windows.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

If the application program is a console program then you may have to have a WinMain() inside the dll and call it from the dll. For example if you have a function named foo() in the dll then foo() would call its WinMain() using HINSTANCE that it gets by calling GetModuleHandle(). You could probably name the function anything you want, I just used WinMain()

Here's an example DLL that I did for this thread. I got some of the code from other threads here at DaniWeb.

#include <stdio.h>
#include <stdlib.h>
#include <windows.h>
#include "mydll.h"

BOOL MakeAWindow(HINSTANCE appInstance,int show);
LRESULT CALLBACK WndProc(HWND window,UINT msg,WPARAM wParam,LPARAM lParam);
HWND MainWindow = 0;

static int*	gInstList	[7]={ 0, 0, 0, 0, 0, 0, 0 };
static int	gInstCnt=0;




int MessageLoop()
{
	MSG msg;
	ZeroMemory(&msg, sizeof(MSG));

	while (GetMessage(&msg, 0, 0, 0))
	{
		TranslateMessage(&msg);
		DispatchMessage(&msg);
	}

return msg.wParam;
}

INT WINAPI WinMain(HINSTANCE hInstance,
                   HINSTANCE hPrevInstance, 
                   LPSTR lpCmdLine,
                   int nShowCmd)
{
	if (!MakeAWindow(hInstance, nShowCmd))
	{
		MessageBox(0, "Window Creation -- Failed", "Error", MB_OK);
		return 0;
	}

return MessageLoop();

}

BOOL MakeAWindow(HINSTANCE appInstance,int show)
{

	WNDCLASS wc;

	wc.style         = CS_HREDRAW | CS_VREDRAW;
	wc.lpfnWndProc   = WndProc;
	wc.cbClsExtra    = 0;
	wc.cbWndExtra    = 0;
	wc.hInstance     = appInstance;
	wc.hIcon         = LoadIcon(0,IDI_APPLICATION);
	wc.hCursor       = LoadCursor(0,IDC_ARROW);
	wc.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH);
	wc.lpszMenuName  = 0;
	wc.lpszClassName = "wc";

	if (!RegisterClass(&wc))
	{
		MessageBox(0, "Failed to register the window class", "Windows Sucks!", 0);
		return FALSE;
	}
	
	MainWindow = CreateWindow("wc",
                                  "Hello",
                                  WS_OVERLAPPEDWINDOW,
				  CW_USEDEFAULT,
				  CW_USEDEFAULT,
				  CW_USEDEFAULT,
				  CW_USEDEFAULT,
				  0,
				  0,
				  appInstance,
				  0);

	if(MainWindow == NULL)
	{
		MessageBox(0,"Function CreateWindow() Failed",0,0);
		return FALSE; …
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>>It means somebody is waiting for someone to reply.
No it doesn't mean that at all. Many times the original poster will make a final post just to say "thanks" to all other posters, then leave without marking the thread solved. So IMO a new link for this purpose would really give you unusable list of threads.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

look at the argument list for the function fun() -- it requires three parameters; two integers and a char*. Now look at how you are trying to call that function in main(). It is only passing one parameter instead of three.

This compiles correctly with vc++ 2010 express. Note the last dimension must be 6 instead of 5 because "13.40" requires 6 bytes including the null terminator.

const char var[][2][6]={ 
    {"1.95","3.70"},
    {"2.40","4.60"},
    {"2.70","5.70"},
    {"6.60","13.40"}
};

void fun(int col,int row,const char *str)
{
}
int main()
{
    fun(0,0,var[0][0]);
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Huh? You may be right, but what does that have to do with the discussion in this thread???

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

I think MASM has a SIZEOF operator that works very much like C and C# sizeof. See this link

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

I would have thought texting is much more popular today than email, twitter or facebook. People are always texting, even while driving (and getting into accidents)

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>> strcpy((char*) &secret_number, aString);
That should fail on most processors. Why? because you can't just simply copy the contents of a string to an integer. The contents of aString have to be converted to int using something like strtol()

[edit]I think this is what Narue was talking about too :)

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

You didn't mention in your original post that you had called that function, so I'm just bringing it to your attention. If you've already called that function then I don't know what the problem could be.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

maybe this tutorial will show you how to do it.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

See the links in my post in your other thread on the same subject (getting WM_INPUT message).

Note that lParam has the handle to the RAWINPUT structure, not a pointer to it. To get the raw data, use the handle in the call to GetRawInputData.

link

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Raw input is available only when the application calls RegisterRawInputDevices with valid device specifications

See this link and read the Remarks at the bottom.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

What processor? There is no such thing on Intel or Intel compatible processors that I'm aware of. Implementing threading in assembly language would be exceedingly difficult. Better to do it in a higher language such as C.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

declare another byte after the array. Get the address of arr and the address of that new byte, then subtract the two addresses.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>>can i get first the values from the yyyy, mm , dd columns, then name column, then phone and then email, and input them into a string?

I don't know -- can you? I can, but I don't know if you can or not. (hint: read the line a word at a time into individual string, then arrange them however you want in the final string.)

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Alternatives are (1) memory mapped files as previously mentioned, and (2) Windows Clipboard. This involves allocating the arrays with GlobalAlloc() instead of malloc() and putting all data into a contiguous block of global memory instead of some sort of linked list where memory is scattered.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Oh shit! you're right, it doesn't work. Back to the drawing board.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

see other thread

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

I just noticed this thread is in the C forum. I could have sworn it was in c++ before, which is why I posted c++ code instead of C code. In any event, making the object static changes nothing because static works pretty much the same in c as it does in c++.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

I vote for all of them because they all do a terrific job keeping out the spam and doing other moderator jobs that we normal people don't see. This poll is nothing more than a popularity contest, not one that tells who puts in the most effort doing mod duties. You should add SOS, Davy and Narue to the list because they also perform mod duties from time to time.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

I just did the same test on Ubuntu using the same source code that I posted earlier and it worked as expected. The only changes I made was, using Code::Blocks, the mydll project was a shared library and I removed all that MYDLL_API macro stuff. Then I launched two terminals, cd's to where the testdll executable was located and ran the same program in both terminals. It produced the same output in both terminals.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Yes, the dll static variable scheme should be fine for Windows. That won't work for other (Unix/Linux) operating systems unfortunately as a static variable declared like that is not shared with other instances of the dll; only the initial value when the variable is initialized will be shared. Changes to the variable will not be.

DLLs are only used in MS-Windows operating system. *nix does not use DLLs, they use shared libraries instead. So AFAIK the problem is not related to *nix.

The definition of static is part of C and C++ standards, so I think it should work the same on all operating systems and compilers. However I have not tested it on only MS-Windows.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Just making the data static in the dll will do the job. Here is a quick test program that I just finished writing to prove the application

// this is the dll. The function dllmain() is generated by the vc++ 2010 express so I did not post it here.

// mydll.cpp
#include <vector>
#include "mydll.h"



static std::vector<int> myvector;


MYDLL_API std::vector<int>& Cmydll::getvector(void)
{
	return myvector;
}

// This is the constructor of a class that has been exported.
// see mydll.h for the class definition
Cmydll::Cmydll()
{
    if( myvector.size() == 0)
    {
        for(int i = 1; i < 20; i++)
            myvector.push_back(i);
    }
	return;
}
// mydll.h
// The following ifdef block is the standard way of creating macros which make exporting 
// from a DLL simpler. All files within this DLL are compiled with the MYDLL_EXPORTS
// symbol defined on the command line. This symbol should not be defined on any project
// that uses this DLL. This way any other project whose source files include this file see 
// MYDLL_API functions as being imported from a DLL, whereas this DLL sees symbols
// defined with this macro as being exported.
#ifdef MYDLL_EXPORTS
#define MYDLL_API __declspec(dllexport)
#else
#define MYDLL_API __declspec(dllimport)
#endif

// This class is exported from the mydll.dll
class MYDLL_API Cmydll {
public:
	Cmydll(void);
    std::vector<int>& getvector();
	// TODO: add your methods here.
};

// Now this is the application program that uses the data in the DLL. Run two or more instances of this program and you …

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

And with his 5th point, to be honest, regular mail is just as bad - in reverse. My wife just got a letter addressed to her using her maiden name. We were married 16 years ago! Isn't it about time that name was removed from mailing lists?

I got a letter awhile ago addressed to my mother-in-law who has been dead over 10 years.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

cin stops reading keyboard input at the first space or the enter key. The next time cin is called it will just take whatever is already in the keybord buffer, if anything. call getline() instead of cin to allow for spaces in the string. getline(cin,record[i].Sno);

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

reg cleaners can do more harm than good. The only time a reg cleaner might be of any value is when you install and uninstall many programs that do not do a good job of cleaning up after themselves during uninstall. And even then its questionable to use one because the cleaner could wipe out important stuff in the registry that other programs may use. But if you want to use a reg cleaner anyway, always back up the registry before doing anything.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

by encoding do you mean how to tell the difference between UNICODE and ascii text? Here is one link that may help you

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

1. The null terminator is a character at the end of the string that contains '\0'. The example you posted could be rewritten like this:

char phrase[13] = {'G','a','m','e',' ','O','v','e','r','!','!','!',','\0'}; Its just a lot more convenient for us to type it as in your example, and the compiler will generate the correct code to null terminate the string.

2. You mean the quotes around [b] "Game Over!!!"[/b]? Yes the quotes are required so that the compiler knows where the beginning and end of the string are.

[edit]^^^ Oops he posted before I did.[icode]
char phrase[13] = {'G','a','m','e',' ','O','v','e','r','!','!','!',','\0'};
Its just a lot more convenient for us to type it as in your example, and the compiler will generate the correct code to null terminate the string.

2. You mean the quotes around "Game Over!!!"? Yes the quotes are required so that the compiler knows where the beginning and end of the string are.


[edit]^^^ Oops he posted before I did.

crapgarden commented: awesome +3
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

You have to use two different arrays. You can't put names (text) in an array of integers

#include <string>

int main()
{
   int scores[5];
   std::string names[5];

...
...
   // swap the two arrays
   if( scores[j+1] > scores[j] )
   {
      std::string tempname;
      int tempscore;
      tempscore = scores[j+1];
      scores[i] = scores[j];
      scores[j] = tempscore;
      // swap the names
      tempname = names[j+1];
      names[i] = names[j];
      names[j] = tempname;
   }
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

or just hide the window

#include <windows.h>
int main()
{
   HWND hWnd = GetConsoleWindow();
   ShowWindow(hWnd,SW_HIDE);
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

There are lots of links that show you how to create makefiles. Here are some of them.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

If you use two arrays, one for the scores and another for the names, during the sort you have to swap both arrays at the same time so that their order remains the same in both arrays. This is one reason why its much simpler to just use an array of structures, then swap the entire structure, all at the same time.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

I never heard of the game crabs, but what is the question/problem with the code you posted?

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

A VARIANT is standard Microsoft structure used to pass object across COM objects. Use heavily in COM programming and to pass strings between VB and c/c++.

The vt member of the VARIANT object tells what kind of object the VARIANT contains. Then the remainder of the structure is a union of several object types, one that is commonly used to pass strings is BSTR. The BSTR itself is commonly encoded with UNICODE strings which are wchar_t* instead of char*. The length of the BSTR is actually a long integer stored 4 bytes before the beginning of the BSTR pointer. So if you want the length of the BSTR then its just like this:

BSTR b = SysAllocString( L"Hello"); // Create a BSTR

long len = *(long *)(b-2);

google will give you links to several threads that indicate how to convert from BSTR to char*. Here is just one of them.

Here is another good tutorial

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

I have not tried it but you might try something as simple as static global memory. MS-Windows does not support shared memory segments like *nix does, unless it may have been added by the .NET framework (I don't know about that). See this link and the links in it.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

You didn't say what operating system you are using. For MS-Windows, VC++ 2010 Express is my first choice, but for cross-platform I use Code::Blocks. If you are also interested in using the same IDE for other languages then Eclipse or NetBeans may be the best choice (although I have not used either).

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

If you want to support any sql-compliant database then use ODBC, which is the oldest and most common way to access them. There are a few free c++ odbc wrapper classes, just use google and you will easily find them. Also you might want to read an odbc tutorial, which again can easily be found with google.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Never use #include to include one *.cpp file in another. If you have two or more *.cpp files then they must be compiled separately and then linked together to create the final executable program.

Your class declaration should be in header files (with *.h extension). You can put them all in the same header file if you wish, or split them up into different header files. For small classes you might as well just put them all in the same header.

To avoid the duplicate declaration error problem you should use header code guards preprocessor directives, as in this example

#ifndef MYHEADER_H
#define MYHEADER_H
// put all your classes and other stuff here

#endif // end of MYHEADER_H
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Yes it was -- but it ran in protected mode so that it could use all that ram.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

There is no such thing as a good gui for MS-DOS Version 6.X or earlier. That's one reason Microsoft evolved into 32-bit protected mode programming and wrote MS-Windows operating system. MS-DOS simply doesn't support enough memory to allow for a GUI environment. About the best you can do is flip the screen into graphics mode and draw a few pretty pictures -- and very very slowly.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

That option is no longer available (in vc++ 2010) because all programs now use the multi-threaded library. See this thread

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

what exactly do you want to do?

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

line 54 is opening the file in text mode, not binary mode. the open flag for binary mode is "rb". Same with lines 91 and 109. Opening the files in text mode on MS-Windows will result in incorrectly reading binary data due to the translation of CR/LF line terminating characters in text files.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Hi all!

I've read forward declaration is much prefered than include in header files mainly because it reduces the compilation time. Other reasons?

My particular situation is that all header files that I use are within a namespace. I've seen two different ways for forward declaration in this case:

namespace n1
{
class c1;
}

and

using namespace n1;
class c1;

I think the first one is better because I don't like the idea of the "using" keyword in a .h file. But with this method 1 line of include is converted into 4 lines for each include

Since I use 5 or more includes of 5 different namespaces the code increases quite a lot.

My question is...
Is there any other way of using this forward declaration but with that increment in source code lines?

any idea?

thank you all in advance!

Your first and second examples are NOT the same thing. In the second example class c1 is not declared to be in the namespace, while in the first example it is.


Lets assume you have this header file

// forward declaration
namespace n2
{
    class c2;
};

// this class uses the forward declaration
namespace n
{
    class c1
    {
    public:
    private:
        n2::c2* pC2; // use forward declaration
    };
};

Now in the *.cpp file just do this

#include "test.h"

int main()
{
    n::c1 object;
}