|
|
As Richard indicates, nothing beats actually writing some code and learning by doing.
There is one book I really like which isn't on the reference page:
"C++/CLI In Action" by Nishant Sivakumar.
|
|
|
|
|
Hi all,
I want to use MD5 to hash message. I see some implementation in the internet but my problem is that my message is not a string but a packet type. Someone can help please?
regards
|
|
|
|
|
Hashing works on bytes, whether they are characters or not is not important.
Veni, vidi, abiit domum
|
|
|
|
|
Well, type of data is not important.
Anyhow you have to send data to MD5 with array so there is no important thing happened when you send char array or byte array.
The difference between your message and string is that use byte array or use char array.
So, you can send byte array which implements your message contents to HD5 instead of char array. That's all.
|
|
|
|
|
#include <stdio.h>
#include<string.h>
char f[10000];
char factorial[1010][10000];
void multiply(int k)
{
int cin,sum,i;
int len = strlen(f);
cin=0;
i=0;
while(i<len)
{
sum=cin+(f[i] - '0') * k;
f[i] = (sum % 10) + '0';
i++;
cin = sum/10;
}
while(cin>0)
{
f[i++] = (cin%10) + '0';
cin/=10;
}
f[i]='\0';
for(int j=0;j<i;j++)
factorial[k][j]=f[j];
factorial[k][i]='\0';
}
void fac()
{
int k;
strcpy(f,"1");
for(k=2;k<=1000;k++)
multiply(k);
}
void print(int n)
{
int i;
int len = strlen(factorial[n]);
printf("%d!\n",n);
for(i=len-1;i>=0;i--)
printf("%c",factorial[n][i]);
printf("\n");
}
int main()
{
int n;
factorial[0][0]='1';
factorial[1][0]='1';
fac();
while(scanf("%d",&n)==1){
print(1);
}
return 0;
}
|
|
|
|
|
And??
cheers,
Super
------------------------------------------
Too much of good is bad,mix some evil in it
|
|
|
|
|
??
What do you want? 
|
|
|
|
|
Beside the fact that no question is asked, there is no CLI in the code; this is all standard C++. I believe this is posted to the wrong forum.
|
|
|
|
|
what is the code all about? Please ask question what do you want.
I love to answer c++ question :P
|
|
|
|
|
Testing started ...
Check for sensible topic name .................. failed!
Check comprehensibility of the question ........ check aborted; missing data!
Check for code example ......................... success!
Check for code readability and documentation ... failed!
Check topic against sub forum type ............. failed!
Test completed.
Test results:
1 success
3 failed
1 aborted
We are sorry to inform you that at this moment there is insufficient data to process your query.
Thank you for using CodeProject Forums.
GOTOs are a bit like wire coat hangers: they tend to breed in the darkness, such that where there once were few, eventually there are many, and the program's architecture collapses beneath them. (Fran Poretto)
|
|
|
|
|
when I debug my app within a break ,"Internal error: pc 0x112 in read in psymtab, but not in symtab"jump out. what's up to my app?
|
|
|
|
|
Looks like you have the wrong forum for this question.
You may get a better response from qtforum.org or stackoverflow.com.
John
|
|
|
|
|
|
Have you got an answer on your question about crash?
I'm having a similar problem and don't know why...
|
|
|
|
|
int _tmain() {
LPCTSTR strName("HideDriver.sys");
utils::DriverWork::Start(strName);
return 0;
}
/*this code causes error LNK2019: unresolved external symbol "public: static void __cdecl utils::DriverWork::Start(char const *)" (?Start@DriverWork@utils@@SAXPBD@Z) referenced in function _main */
it builds fine by including DriverWork.cpp but does not build by only including DriverWork.h,,,,???
|
|
|
|
|
af00001 wrote: it builds fine by including DriverWork.cpp but does not build by only including DriverWork.h,,,,??? The .h files do not get actioned by the build system or compiler, only insofar as they are included into the source via the .cpp files. The compiler will only get executed to convert a .cpp file (and its inclusions) into object code.
Veni, vidi, abiit domum
|
|
|
|
|
|
This looks more like unmanaged C++ than managed. You need to include the .lib file of the dll the function resides in into the linker input of your application.
The good thing about pessimism is, that you are always either right or pleasently surprised.
|
|
|
|
|
Freak30 wrote: This looks more like unmanaged C++ than managed. Not at all. The key is that the code is contained within the header file, so why is the .cpp file necessary. That's the way C++/CLI is done.
Veni, vidi, abiit domum
|
|
|
|
|
|
thnx,,,,but i am not sure which lib needs to include 
|
|
|
|
|
Well, did you add DriverWork.cpp to your solution?
Well, I was experienced problem like you. Cause of error is that I include header file using #include keyword but know added header and source file to my solutions. Whenever I've added it to my solutions, error disappeared.

|
|
|
|
|
|
The below is GList.H
#ifndef __GLIST_H
#define __GLIST_H
#include <assert.h>
#include <STDIO.H>
#include <STDLIB.H>
#include <STRING.H>
#include <STRNG.H>
#include <MALLOC.H>
typedef enum bool { false, true};
class GList
{
private:
char **arr;
int length;
void FillEmptyAll(int);
void ResizeList(int);
void SetArr(char **);
void SetLen(size_t);
char **GetArr() { return arr; }
public:
size_t GetLen();
void Add(const char*);
void Add(String);
void SetValue(size_t, const char*);
void SetValue(size_t, String);
char* GetValue(size_t);
void InsertValue(size_t, const char*);
void InsertValue(size_t, String);
void FillEmptyRange(size_t, size_t);
void CreateMemList(size_t);
void RemoveAt(size_t);
void RemoveRange(size_t, size_t);
void RemoveValue(const char *);
void RemoveValue(String);
void RemoveAllValue(const char *);
void RemoveAllValue(String);
GList();
GList(const GList& L); GList& operator=(const GList& L); virtual ~GList();
};
inline GList::GList(void)
{
length = 1;
arr = (char**) malloc(sizeof(char*) * length);
}
inline GList::GList(const GList& L): length(L.length),
arr((char**)malloc(sizeof(char*) * L.length))
{
int idx = L.length - 1;
for(int i = 0; i < idx; i++){
*(arr + i) = *(L.arr + i);
}
*(arr + idx) = 0;
}
inline GList& GList::operator=(const GList& L)
{
if (this == &L) return *this;
else
{
length = L.length;
if (arr != 0)
{
free(arr);
arr = 0;
}
arr = (char**)malloc(sizeof(char*) * L.length);
int idx = L.length - 1;
for(int i = 0; i < idx; i++)
*(arr + i) = *(L.arr + i);
*(arr + idx) = 0;
}
return *this;
}
inline GList::~GList()
{
if (arr != 0)
{
free(arr);
}
printf("Destructor GList");
}
void GList::FillEmptyAll(int len)
{
for(int i = 0; i < len; i++)
*(arr + i) = strdup("");
*(arr + len) = 0;
}
void GList::FillEmptyRange(size_t startAt, size_t startEnd)
{
if (startEnd - startAt <= 0) return;
for(int i = startAt; i < startEnd; i++)
SetValue(i, "");
}
void GList::CreateMemList(size_t numData)
{
if (numData == 0 || numData == 1)
{
length = 1;
if (arr != 0)
free(arr);
arr = (char**) malloc(sizeof(char*) * length);
}
else
{
length = numData;
if (arr != 0)
{
free(arr);
arr = 0;
}
arr = (char**) malloc(sizeof(char*) * length);
if (arr == 0)
{
printf("Create new memory for List failed! Not enough memory");
abort();
}
FillEmptyAll(length - 1);
}
}
size_t GList::GetLen(void)
{
if (length == 0)
return 0;
return length-1;
}
void GList::SetValue(size_t index, const char *value)
{
if (index >= GetLen())
return;
else
*(arr + index) = strdup(value);
}
void GList::SetValue(size_t index, String value)
{
char *string = strdup(value);
SetValue(index, string);
if (string != NULL)
delete string;
}
void GList::SetLen(size_t newlength)
{
if (newlength <= 1)
length = 1;
length = newlength;
}
void GList::SetArr(char **array)
{
arr = array;
}
char* GList::GetValue(size_t index)
{
if (index >= GetLen() || index < 0)
return NULL;
else
return *(arr + index);
}
void GList::InsertValue(size_t index, const char *value)
{
char **newarr = 0;
int i;
int newLen = 0;
int idx = 0;
int oldLen = length - 1;
if (index > oldLen || index < 0)
return;
length = length + 1;
idx = length - 1;
newarr = (char**) malloc(sizeof(char*) * length);
if (newarr == 0)
{
printf("Insert new value to List failed! Not enought memory.");
abort();
}
for(i = 0; i < index; i++)
*(newarr + i) = *(arr + i);
for(i = idx - 1; i > index; i--)
*(newarr + i) = *(arr + (i-1));
*(newarr + index) = strdup(value);
assert(idx = length - 1);
*(newarr + idx) = 0;
if (arr != 0)
{
free(arr);
arr = 0;
}
arr = newarr;
newarr = 0;
if (newarr == 0)
delete newarr;
}
void GList::InsertValue(size_t index, String value)
{
char *str = strdup(value);
InsertValue(index, str);
if (str != NULL)
delete str;
}
void GList::Add(const char *value)
{
int idx = length - 1;
if (idx <= 0)
{
length = 2;
if (arr != 0)
{
free(arr);
arr = 0;
}
arr = (char**) malloc(sizeof(char*) * length);
if (arr == 0)
{
printf("Add new value to List failed!");
abort();
}
*(arr + 0) = strdup(value);
*(arr + (length -1)) = 0;
}
else if (idx >= 1)
{
length++;
char **newarr = 0;
newarr = (char**) malloc(sizeof(char*) * length);
if (newarr == 0)
{
printf("Add new value to List failed!\n");
abort();
}
for(int i = 0; i < idx; i++)
*(newarr + i) = *(arr + i);
*(newarr + idx++) = strdup(value);
assert(idx = length - 1);
*(newarr + idx) = 0;
if (arr != 0)
{
free(arr);
arr = 0;
}
arr = newarr;
newarr = 0;
if (newarr == 0)
delete newarr;
}
}
void GList::Add(String value)
{
char *str = strdup(value);
Add(str);
if (str != NULL)
delete str;
}
void GList::RemoveAt(size_t index)
{
int i, idx;
int len = length - 1;
idx = length - 1;
if (index >= len || idx == 0)
return;
for(i = index; i < idx - 1; i++)
{
*(arr + i) = *(arr + (i+1));
}
length = length - 1;
char **newarr;
newarr = (char**) malloc(sizeof(char*) * length);
if (newarr == NULL)
{
printf("Remove at index %i in List failed!", index);
abort();
}
idx = idx - 1;
for(i = 0; i < idx; i++)
*(newarr + i) = *(arr + i);
assert(idx = length - 1);
*(newarr + idx) = 0;
if (arr != 0)
{
free(arr);
arr = 0;
}
arr = newarr;
newarr = 0;
if (newarr == 0)
delete newarr;
}
void GList::RemoveRange(size_t startAt, size_t startEnd)
{
int oldLen = length - 1;
int numRemoveData = startEnd - startAt + 1;
int numMoveData = oldLen - numRemoveData - startAt;
int index = 0;
int lock = 0;
if ((numRemoveData < 0) || startEnd > oldLen -1)
return;
for(index = 0; index < numMoveData; index++)
*(arr + (index + startAt)) = *(arr + (startEnd + index + 1));
if (startEnd == oldLen - 1)
lock = startAt;
else if (startEnd < oldLen - 1)
lock = startAt + numMoveData;
length = length - numRemoveData;
if (length <= 1)
{
free(arr);
arr = 0;
length = 1;
}
else if (length > 1)
{
char** newarr= 0;
newarr = (char**) malloc(sizeof(char*) * length);
if (newarr == 0)
{
printf("Remove range %i to %i from List failed!",startAt, startEnd);
abort();
}
for(index = 0; index < lock; index++)
*(newarr + index) = *(arr + index);
assert(lock = length - 1);
*(newarr + lock) = 0;
if (arr != 0)
{
free(arr);
arr = 0;
}
arr = newarr;
newarr = 0;
if (newarr == 0)
delete newarr;
}
}
void GList::RemoveValue(const char *value)
{
int pos = 0;
int index = 0;
bool found = false;
int len = length - 1;
if ((value == NULL) || (len == 0)) return;
while ((index < len) && !found)
{
pos = strcmp(arr[index],value);
if (pos == 0)
found = true;
else
index++;
}
if (found)
RemoveAt(index);
}
void GList::RemoveValue(String value)
{
char *str = strdup(value);
RemoveValue(str);
if (str != NULL)
delete str;
}
void GList::RemoveAllValue(const char *string)
{
int index = 0;
int pos = 0;
if (string == NULL) return;
while (index < GetLen())
{
pos = strcmp(*(arr + index), string);
if (pos == 0)
RemoveAt(index);
else
index++;
}
}
void GList::RemoveAllValue(String string)
{
char *str = strdup(string);
RemoveAllValue(str);
if (str != NULL)
delete str;
}
#endif
/* -------------------------------------------------------------- */
/* INIClass.H */
/* Author : Nguyen Hong Phuc */
/* Copyright c 2013 */
/* -------------------------------------------------------------- */
#ifndef __INICLASS_H
#define __INICLASS_H
#include "HPCLASS.H"
#include <stdio.h>
#include <fcntl.h>
#include <sys\stat.h>
#include <io.h>
typedef enum ErrorCode {
Success = 0,
Invalid_PathFile = 1,
Invalid_Command = 2,
Invalid_Key = 4,
Invalid_Subkey = 6,
Invalid_CreateFile = 8,
Invalid_FileExisted = 10,
Invalid_FileName = 12,
Invalid_Parameters = 14,
Unknown_Error = 16
};
There is INIClass :
class INIClass : public GList
{
private:
GList fLines;
GList pList;
char *PathFileName;
char *cmdT;
ErrorCode error;
void InitStringProtocol();
void InitStringSystem();
int Initialize();
int CreateProtocol();
int CreateSystem();
int ReadFromFile();
int WriteToFile();
void CommandCreate(const char*);
public:
int Finaliaze();
//INIClass(char *[]);
INIClass(GList);
~INIClass();
};
inline INIClass::INIClass(GList mList)
{
error = Success;
PathFileName = "";
cmdT = "";
pList = mList;
pList.RemoveAt(0);
PathFileName = pList.GetValue(0);
pList.RemoveAt(0);
cmdT = pList.GetValue(0);
pList.RemoveAt(0);
//fLines.Add(" ");
//Initialize();
//fLines = NULL;
}
/* Deconstructor for INIClass */
inline INIClass::~INIClass(void)
{
//delete error;
//delete cmdT;
//delete PathFileName;
printf("\nDestructor INIClass.\n");
}
/* ------------- Define Property and Function for INIClass ----------------- */
int INIClass::Finaliaze(void)
{
int exit_code = 0;
return exit_code = Initialize();
}
int INIClass::Initialize()
{
int iType = -1;
char *cmdType[] = {"create", "remove", "read", "write", "edit"};
for(int i = 0; i < sizeof(cmdType) / sizeof(cmdType[0]); i++)
{
if (strcmp(cmdType[i], Trim(cmdT)) == 0)
{
iType = i;
break;
}
}
switch (iType)
{
case 0: //create
if (pList.GetLen() == 0)
error = Invalid_Parameters;
else
{
printf("Command Create is call.");
CommandCreate(pList.GetValue(0));
}
break;
default:
error = Invalid_Parameters;
break;
}
return error;
}
/* Initilize for Protocol */
void INIClass::InitStringProtocol()
{
fLines.Add("; Protocol.ini auto generated by NETCFG - File created by Hong Phuc");
fLines.Add("; ONLY SUPPORT FOR MYSELF, IF NEED TO USE PLEASE RE-EDIT");
fLines.Add("; PLEASE DO NOT REMOVE ANY LINE BELOW");
fLines.Add("[network.setup]");
fLines.Add("version=0x3110");
fLines.Add("netcard=hp2$nic,1,HP2$NIC,1");
fLines.Add("transport=hp2$ndishlp,HP2$NDISHLP");
fLines.Add("transport=hp2$netbeui,HP2$NETBEUI");
fLines.Add("lana0=hp2$nic,1,hp2$netbeui");
fLines.Add("lana1=hp2$nic,1,hp2$ndishlp");
//fLines.Add("\n");
fLines.Add("[HP2$NETBEUI]");
fLines.Add("NCBS=8");
fLines.Add("SESSIONS=3");
fLines.Add("DRIVERNAME=netbeui$");
fLines.Add("BINDINGS=HP2$NIC");
fLines.Add("LANABASE=0");
//fLines.Add("\n");
fLines.Add("[PROTMAN]");
fLines.Add("DriverName=PROTMAN$");
fLines.Add("PRIORITY=PKTDRV$");
//fLines.Add("\n");
fLines.Add("[PKTDRV]");
fLines.Add("DriverName=PKTDRV$");
fLines.Add("BINDINGS=HP2$NIC");
fLines.Add("intvec=0x60");
fLines.Add("chainvec=0x66");
//fLines.Add("\n");
fLines.Add("[HP2$NDISHLP]");
fLines.Add("DriverName=ndishlp$");
fLines.Add("BINDINGS=HP2$NIC");
//fLines.Add("\n");
fLines.Add("[HP2$NIC]");
}
/* Initialize for System */
void INIClass::InitStringSystem()
{
fLines.Add("; System.ini auto generated by NETCFG - File created by Hong Phuc");
fLines.Add("; ONLY SUPPORT FOR MYSELF, IF NEED TO USE PLEASE RE-EDIT.");
fLines.Add("; PLEASE DO NOT REMOVE ANY LINE BELOW");
fLines.Add("[386enh]");
fLines.Add("TimerCriticalSection=5000");
fLines.Add("UniqueDosPSP=TRUE");
fLines.Add("PSPIncrement=2");
//fLines.Add("\n");
fLines.Add("[network]");
fLines.Add("filesharing=no");
fLines.Add("printsharing=no");
fLines.Add("autologon=no");
fLines.Add("reconnect=yes");
fLines.Add("dospophotkey=N");
fLines.Add("lmlogon=<edit_by_netcfg>");
fLines.Add("preferredredir=<edit_by_netcfg>");
fLines.Add("autostart=<edit_by_netcfg>");
fLines.Add("maxconnections=8");
fLines.Add("sizworkbuff=1498");
//fLines.Add("\n");
fLines.Add("username=<edit_by_netcfg>");
fLines.Add("workgroup=<edit_by_netcfg>");
fLines.Add("computername=<edit_by_netcfg>");
fLines.Add("lanroot=<edit_by_netcfg>");
//fLines.Add("\n");
fLines.Add("[network drivers]");
fLines.Add("LoadRMDrivers=yes");
fLines.Add("transport=<edit_by_netcfg>");
fLines.Add("netcard=<edit_by_netcfg>");
fLines.Add("devdir=<edit_by_netcfg>");
}
//This function is create the Protocol.ini file
int INIClass::CreateProtocol(void)
{
printf("Creating Protocol.");
if (!Contains(PathFileName, "\\protocol.ini"))
{
if (!EndWith(PathFileName, "\\"))
PathFileName = strcat(PathFileName, "\\protocol.ini");
else
PathFileName = strcat(PathFileName, "protocol.ini");
}
if (FileExist(PathFileName))
error = Invalid_FileExisted;
else
{
InitStringProtocol();
error = WriteToFile();
}
return error;
}
//This function is create the System.ini file
int INIClass::CreateSystem(void)
{
//string strPathFile = PathFile;
if (!Contains(PathFileName, "\\system.ini"))
{
if (!EndWith(PathFileName, "\\"))
PathFileName = strcat(PathFileName, "\\system.ini");
else
PathFileName = strcat(PathFileName, "system.ini");
}
if (FileExist(PathFileName))
error = Invalid_FileExisted;
else
{
InitStringSystem();
error = WriteToFile();
}
return error;
}
int INIClass::ReadFromFile()
{
FILE *fname;
char data[256];
fname = fopen(PathFileName, "r");
if (fname != NULL)
{
while (!feof(fname))
{
fgets(data, 256, fname);
fLines.Add(Trim(data));
}
fclose(fname);
error = Success;
}
else
error = Invalid_PathFile;
return error;
}
int INIClass::WriteToFile()
{
FILE *stream;
printf("WTF call, PathFile = %s\n",PathFileName);
if (FileExist(PathFileName))
{
if (remove(PathFileName) == -1)
return error = Invalid_FileName;
}
stream = fopen(PathFileName, "wt");
if (stream != NULL)
{
for (int i = 0; i < fLines.GetLen(); i++)
{
char *value = fLines.GetValue(i);;
//write(handle, value, strlen(value));
fprintf(stream, value);
fprintf(stream, "\n");
}
fclose(stream);
error = Success;
}
else
error = Invalid_PathFile;
return error;
}
//This function is create an Protocol.ini/System.ini. Return : 0 - success
void INIClass::CommandCreate(const char *strType)
{
int iType = -1;
char *ctype[] = {"pro", "protocol", "sys", "system"};
for(int i = 0; i < sizeof(ctype) / sizeof(ctype[0]); i++)
{
if (strcmp(ctype[i], Trim(strType)) == 0)
{
iType = i;
break;
}
}
switch (iType)
{
case 0:
case 1:
printf("Create Protocol");
error = CreateProtocol();
break;
case 2:
case 3:
error = CreateSystem();
break;
default:
error = Invalid_Command;
break;
}
}
/* ----------------- End of INIClass --------------- */
#endif
#include <iniclass.h>
#include <hpclass.h>
#include <stdio.h>
#include <conio.h>
void main(int argc, char* argv[])
{
//clrscr();
int exit = 0;
GList mList(Split(argv));
INIClass ini(mList);
exit = ini.Finaliaze();
printf("\nEnd program - Exit code : %i",exit);
//delete ini;
}
When Compile and Run with arguments :
c:\Testini.exe c:\obj create protocol
The file c:\obj\protocol.ini is created but Null pointer assignments is display. I don't know why.
|
|
|
|
|