Quantcast
Channel: CodeGuru Forums - Visual C++ Programming
Viewing all 3020 articles
Browse latest View live

How new/delete stores the internal info about the allocated buffer?

$
0
0
I am using C++ new/delete operators to allocate/deallocate the buffers. I think for each allocated buffer, there should be an additional info block stores the size and other info about the buffer. How to know more details about this info block? I need to override these two operators and find such an info block is useful to my implementation.

Thanks

partitioning USB Falsh drive

$
0
0
I have written some code to make two partitions in USB flash drive. When I ran it I am not able to make partitions on usb. What'll be the problem in this code.
Code:

/-------------------INITIALIZE AND PARTITION-------------------------------//
#include "stdafx.h"                                                                 
#include <Windows.h>                                                           
#include <stdio.h>                                                                 
#include <iostream>                                                               
#include <tchar.h>                                                               
#include <winioctl.h>                                                           
#include <shellapi.h>                                                           
//-------------------------------------Main-------------------------------------//
int _tmain(int argc, _TCHAR* argv[])                                                                   
{                                                                               
        //char *dsk = "\\\\.\\PhysicalDrive1";                                       
        HANDLE hDisk;                                                               
        DWORD junk = 0;                                                               
        BOOL bResult = false;   
        unsigned int SectorSize = 512;
//
        //
        hDisk = CreateFile(TEXT("\\\\.\\E:"),                           
                GENERIC_READ | GENERIC_WRITE,                                         
                FILE_SHARE_READ | FILE_SHARE_WRITE,                                       
                NULL,                                                                   
                OPEN_EXISTING,                                                           
                0,                                                                       
                NULL);                                                                   
        //
        //error handler for driver                                                   
        if (hDisk == INVALID_HANDLE_VALUE)                                             
        {                                                                           
                CloseHandle(hDisk);                                                       
                return 1;                                                               
        }                                                                           
        //
        //
        CREATE_DISK dsk;                                                           
        dsk.PartitionStyle = PARTITION_STYLE_MBR;                                   
        dsk.Mbr.Signature = 9999;                                                   
        //
        //-------------------------------Initialize Disk--------------------------------//
        bResult = DeviceIoControl(hDisk,    //initialize raw disk                   
                IOCTL_DISK_CREATE_DISK,                                                   
                &dsk, sizeof(dsk),                                                       
                NULL, 0,                                                               
                &junk,                                                                   
                NULL);                                                                   
        //
        if (!bResult)                                                               
        {                                                                           
                return GetLastError();                                                   
        }                                                                           
        //
        bResult = DeviceIoControl(hDisk,    //to flush changes                       
                IOCTL_DISK_UPDATE_PROPERTIES,                                           
                NULL, 0, NULL, 0, &junk, NULL);                                           
        //
        if (!bResult)                                                               
        {                                                                           
                return GetLastError();                                                   
        }                                                                           
        //
        //
        //----------------------------Partition Disk--------------------------------//
        LARGE_INTEGER DiskSize;
        DiskSize.QuadPart = 15784004812.8;
                LARGE_INTEGER Part_1_size;
                Part_1_size.QuadPart = 7892002406.4;
                LARGE_INTEGER Part_2_size;
                Part_2_size.QuadPart = 7892002406.4;
        LARGE_INTEGER lgPartSize;                                                   
        //
        lgPartSize.QuadPart = (1024 * 1024 * 1024);                                   
        //
        DWORD dwDriverLayoutInfoExLen = sizeof(DRIVE_LAYOUT_INFORMATION_EX) + 3 *   
                sizeof(PARTITION_INFORMATION_EX);                                       
        //
        DRIVE_LAYOUT_INFORMATION_EX *pdg = (DRIVE_LAYOUT_INFORMATION_EX *)new       
                BYTE[dwDriverLayoutInfoExLen];                                           
        //
        if (pdg == NULL)                                                           
        {                                                                           
                return -1;                                                               
        }                                                                           
        //
        SecureZeroMemory(pdg, dwDriverLayoutInfoExLen);                               
       

        //Create the PHTSYS partition
        pdg->PartitionEntry[0].PartitionStyle = PARTITION_STYLE_MBR;
        pdg->PartitionEntry[0].StartingOffset.QuadPart = 32768;
        pdg->PartitionEntry[0].PartitionLength = Part_1_size;
        pdg->PartitionEntry[0].PartitionNumber = 1;
        pdg->PartitionEntry[0].RewritePartition = 1;
        pdg->PartitionEntry[0].Mbr.PartitionType = PARTITION_FAT32;
        pdg->PartitionEntry[0].Mbr.BootIndicator = TRUE;
        pdg->PartitionEntry[0].Mbr.RecognizedPartition = 1;
        pdg->PartitionEntry[0].Mbr.HiddenSectors = (pdg->PartitionEntry[0].StartingOffset.QuadPart - 1) / SectorSize;

        //Create the extended entry for the PHTDATA partition
        pdg->PartitionEntry[1].PartitionStyle = PARTITION_STYLE_MBR;
        pdg->PartitionEntry[1].StartingOffset.QuadPart = Part_1_size.QuadPart + pdg->PartitionEntry[0].StartingOffset.QuadPart;
        pdg->PartitionEntry[1].PartitionLength = Part_2_size;
        pdg->PartitionEntry[1].PartitionNumber = 2;
        pdg->PartitionEntry[1].RewritePartition = 1;
        pdg->PartitionEntry[1].Mbr.PartitionType = PARTITION_EXTENDED;
        pdg->PartitionEntry[1].Mbr.BootIndicator = 0;
        pdg->PartitionEntry[1].Mbr.RecognizedPartition = 1;
        pdg->PartitionEntry[1].Mbr.HiddenSectors = (pdg->PartitionEntry[0].StartingOffset.QuadPart + Part_1_size.QuadPart) / SectorSize;

        //Create the PHTDATA partition
        pdg->PartitionEntry[4].PartitionStyle = PARTITION_STYLE_MBR;


        pdg->PartitionEntry[4].StartingOffset.QuadPart = Part_1_size.QuadPart + pdg->PartitionEntry[0].StartingOffset.QuadPart + SectorSize;

        LARGE_INTEGER LogicalPartition = Part_2_size;

        LogicalPartition.QuadPart = LogicalPartition.QuadPart - SectorSize;
        pdg->PartitionEntry[4].PartitionNumber = 3;
        pdg->PartitionEntry[4].RewritePartition = 1;
        pdg->PartitionEntry[4].Mbr.PartitionType = PARTITION_FAT32;
        pdg->PartitionEntry[4].Mbr.BootIndicator = 0;
        pdg->PartitionEntry[4].Mbr.RecognizedPartition = 1;
        pdg->PartitionEntry[4].Mbr.HiddenSectors = (pdg->PartitionEntry[0].StartingOffset.QuadPart + Part_1_size.QuadPart) / SectorSize;
        bResult = DeviceIoControl(hDisk,            //device to be queried           
                IOCTL_DISK_SET_DRIVE_LAYOUT_EX,            //operation to perform           
                pdg, sizeof DRIVE_LAYOUT_INFORMATION_EX,//sizeof(pdg),                 
                NULL, 0,                                // output buffer               
                &junk,                                    //# bytes returned               
                NULL);                                                                 
       
        if (!bResult)                                                               
        {                                                                           
                return GetLastError();                                                   
        }                                                                           
        //
        //
        CloseHandle(hDisk);
        return 0;                                                                                   
}

Writing to a named pipe coming from a service (session 0) without admin rights

$
0
0
Greetings

I'm trying to write to a named pipe created by a service, as we all know the session 0 isolation implemented in vista and forward makes this task a bit complicated.

well at this point i managed to make almost all to work but my real problem comes when i try to write on the named pipe from my GUI application with no administrator rights

If i run the GUI application with admin rights it works 100% but, I don't need that application to require the user admin rights and for security reasons i rather to leave it without admin...

so i started my research and i found that there is a way to achieve this by calling CreateNamedPipe() with a low integrity security attributes...

well it was kind a pain in the *** to implement but i finally made it, the problem is that it gets worse than passing null security attributes, it works with admin rights with NULL security attributes, but when i pass the low integrity security attributes it gives "access denied" even when using admin rights, so i guess im passing the wrong security attributes but to be honest i have no idea how to manually create the security descriptor string.


this is the code:

Service (session0) SERVER

Code:

        DWORD WINAPI PipeThreadRSVS(void* pParameter){
        LPTSTR _PIPE_NAME = "\\\\.\\pipe\\RSVHPipeIn";
        bool Break=false;
        char Received_Buffer[BlockSize+16];
        DWORD BytesRead = 0;



        //DYNAMIC CALL
      ConvertStringSecurityDescriptorToSecurityDescriptorT DConvertStringSecurityDescriptorToSecurityDescriptor;

        HMODULE hAdvapi32=LoadLibrary("Advapi32.dll");

        DConvertStringSecurityDescriptorToSecurityDescriptor=(ConvertStringSecurityDescriptorToSecurityDescriptorT)GetProcAddress(hAdvapi32, "ConvertStringSecurityDescriptorToSecurityDescriptorA");


    //

    //SECURIRY DECRIPTOR
    #define LOW_INTEGRITY_SDDL_SACL      "S:(ML;;NW;;;LW)"
    PSECURITY_DESCRIPTOR pSD;
    DConvertStringSecurityDescriptorToSecurityDescriptor(LOW_INTEGRITY_SDDL_SACL,1,&pSD,NULL);

    SECURITY_ATTRIBUTES  sa;
    sa.nLength = sizeof(sa); 
    sa.lpSecurityDescriptor = pSD;
    sa.bInheritHandle = TRUE;



        //hPIPEInRSVS = CreateNamedPipe(_PIPE_NAME,PIPE_ACCESS_INBOUND,PIPE_TYPE_MESSAGE |PIPE_READMODE_MESSAGE | PIPE_WAIT,PIPE_UNLIMITED_INSTANCES,1024,1024,10000,&sa);

        hPIPEInRSVS = CreateNamedPipe(_PIPE_NAME,PIPE_ACCESS_INBOUND,PIPE_TYPE_MESSAGE |PIPE_READMODE_MESSAGE | PIPE_WAIT,PIPE_UNLIMITED_INSTANCES,1024,1024,10000,NULL);


        if ( hPIPEInRSVS != INVALID_HANDLE_VALUE ){
                //OVERLAPPED *Overlapped;

                int Connected = 0;
                Connected = ConnectNamedPipe(hPIPEInRSVS, NULL);
                while(!Break){

                        if ( Connected == 1 ){
                                BOOL bRead = ReadFile(hPIPEInRSVS, Received_Buffer, BlockSize+16, &BytesRead, NULL );

                                if (bRead != 0){
                                        Received_Buffer[7]=0;
                                        PipeRSV* IncPck=(PipeRSV*)&Received_Buffer;
                                        if(strncmp(IncPck->Sig,"EndPCOm",7)==0){//Detenemos la comunicacion
                                          Break=true;
                                        }
                                        PipeMessagesRSVS(IncPck->Sig,IncPck->Data,IncPck->PckSize,IncPck->BlockPos);
                                  //FlushFileBuffers(hPIPE);
                                       
                                }else{
                                    Fncs.Loguear("ReadFile: Failed Server PipeIn");
                    Break=true;
                                }
                        }else{
                                Fncs.Loguear("ConnectedNamePipe() Has been Disconected");
                                Break=true;
                        }
                }//while
        }else{
                Fncs.Loguear("SERVER FAILED ON CreateNamedPipe()");
        }//Luego del Break desconectamos y cerramos el handle

        Fncs.Loguear("Disconecting... Server PipeIn");
    DisconnectNamedPipe(hPIPEInRSVS);
        CloseHandle(hPIPEInRSVS);
        return 0;

}


CLIENT WITH NO ADMIN RIGHTS
Code:

BOOL SendPipeMsgRSVC(char* Sig,char* Message,DWORD BlockPos,int Len){
        if(hPIPEOutRSVC==INVALID_HANDLE_VALUE){
                Fncs.Loguear("CLIENT: The Pipe Hasnt been started!");
                RsvStopFlag=true;
                return FALSE;
        }

        BOOL bWrite = false;
        DWORD BYTESWRITTEN = 0;

        char buffer[BlockSize+16];
        PipeRSV* SendPck=(PipeRSV*)&buffer;
        //copy string into buffer and fill with terminating null characters
        memcpy(SendPck->Sig,Sig,8);
        SendPck->BlockPos=BlockPos;
    SendPck->PckSize=(DWORD)Len;
        memcpy(SendPck->Data,Message,Len);
       
        if ( hPIPEOutRSVC != INVALID_HANDLE_VALUE ){
                //Write char array "buffer" to the pipe handle held in hPIPE
                bWrite = WriteFile( hPIPEOutRSVC, buffer, sizeof(buffer), &BYTESWRITTEN, NULL );

                if ( bWrite == FALSE ){
                        Fncs.Loguear("WriteFile() Error:",GetLastError());
                        RsvStopFlag=true; //we exit every thread
                }
                return bWrite;
        }else{
                Fncs.Loguear("CREATEFILE FAILED!",GetLastError());;
                RsvStopFlag=true;
                CloseHandle(hPIPEOutRSVC);
                return FALSE;
        }


}


BOOL StartPipeRSVC(){
        LPCTSTR _PIPE_NAME = "\\\\.\\pipe\\RSVHPipeIn";
        hPIPEOutRSVC = CreateFile(_PIPE_NAME, GENERIC_WRITE,0, NULL, OPEN_EXISTING,0, NULL);
        if(hPIPEOutRSVC==INVALID_HANDLE_VALUE){
                                       
                    char B[80];
                        sprintf(B, "Client:Pipe Coulnt Be Started: %d", GetLastError());
                        OutputDebugString(B);

                Fncs.Loguear("Client:Pipe Coulnt Be Started",GetLastError());
                RsvStopFlag=true;
                return FALSE;
        }else{
        return TRUE;
        }

Thx in advance

[RESOLVED] Writing to a named pipe coming from a service (session 0) without admin rights

$
0
0
Greetings

I'm trying to write to a named pipe created by a service, as we all know the session 0 isolation implemented in vista and forward makes this task a bit complicated.

well at this point i managed to make almost all to work but my real problem comes when i try to write on the named pipe from my GUI application with no administrator rights

If i run the GUI application with admin rights it works 100% but, I don't need that application to require the user admin rights and for security reasons i rather to leave it without admin...

so i started my research and i found that there is a way to achieve this by calling CreateNamedPipe() with a low integrity security attributes...

well it was kind a pain in the *** to implement but i finally made it, the problem is that it gets worse than passing null security attributes, it works with admin rights with NULL security attributes, but when i pass the low integrity security attributes it gives "access denied" even when using admin rights, so i guess im passing the wrong security attributes but to be honest i have no idea how to manually create the security descriptor string.


this is the code:

Service (session0) SERVER

Code:

        DWORD WINAPI PipeThreadRSVS(void* pParameter){
        LPTSTR _PIPE_NAME = "\\\\.\\pipe\\RSVHPipeIn";
        bool Break=false;
        char Received_Buffer[BlockSize+16];
        DWORD BytesRead = 0;



        //DYNAMIC CALL
      ConvertStringSecurityDescriptorToSecurityDescriptorT DConvertStringSecurityDescriptorToSecurityDescriptor;

        HMODULE hAdvapi32=LoadLibrary("Advapi32.dll");

        DConvertStringSecurityDescriptorToSecurityDescriptor=(ConvertStringSecurityDescriptorToSecurityDescriptorT)GetProcAddress(hAdvapi32, "ConvertStringSecurityDescriptorToSecurityDescriptorA");


    //

    //SECURIRY DECRIPTOR
    #define LOW_INTEGRITY_SDDL_SACL      "S:(ML;;NW;;;LW)"
    PSECURITY_DESCRIPTOR pSD;
    DConvertStringSecurityDescriptorToSecurityDescriptor(LOW_INTEGRITY_SDDL_SACL,1,&pSD,NULL);

    SECURITY_ATTRIBUTES  sa;
    sa.nLength = sizeof(sa); 
    sa.lpSecurityDescriptor = pSD;
    sa.bInheritHandle = TRUE;



        //hPIPEInRSVS = CreateNamedPipe(_PIPE_NAME,PIPE_ACCESS_INBOUND,PIPE_TYPE_MESSAGE |PIPE_READMODE_MESSAGE | PIPE_WAIT,PIPE_UNLIMITED_INSTANCES,1024,1024,10000,&sa);

        hPIPEInRSVS = CreateNamedPipe(_PIPE_NAME,PIPE_ACCESS_INBOUND,PIPE_TYPE_MESSAGE |PIPE_READMODE_MESSAGE | PIPE_WAIT,PIPE_UNLIMITED_INSTANCES,1024,1024,10000,NULL);


        if ( hPIPEInRSVS != INVALID_HANDLE_VALUE ){
                //OVERLAPPED *Overlapped;

                int Connected = 0;
                Connected = ConnectNamedPipe(hPIPEInRSVS, NULL);
                while(!Break){

                        if ( Connected == 1 ){
                                BOOL bRead = ReadFile(hPIPEInRSVS, Received_Buffer, BlockSize+16, &BytesRead, NULL );

                                if (bRead != 0){
                                        Received_Buffer[7]=0;
                                        PipeRSV* IncPck=(PipeRSV*)&Received_Buffer;
                                        if(strncmp(IncPck->Sig,"EndPCOm",7)==0){//Detenemos la comunicacion
                                          Break=true;
                                        }
                                        PipeMessagesRSVS(IncPck->Sig,IncPck->Data,IncPck->PckSize,IncPck->BlockPos);
                                  //FlushFileBuffers(hPIPE);
                                       
                                }else{
                                    Fncs.Loguear("ReadFile: Failed Server PipeIn");
                    Break=true;
                                }
                        }else{
                                Fncs.Loguear("ConnectedNamePipe() Has been Disconected");
                                Break=true;
                        }
                }//while
        }else{
                Fncs.Loguear("SERVER FAILED ON CreateNamedPipe()");
        }//Luego del Break desconectamos y cerramos el handle

        Fncs.Loguear("Disconecting... Server PipeIn");
    DisconnectNamedPipe(hPIPEInRSVS);
        CloseHandle(hPIPEInRSVS);
        return 0;

}


CLIENT WITH NO ADMIN RIGHTS
Code:

BOOL SendPipeMsgRSVC(char* Sig,char* Message,DWORD BlockPos,int Len){
        if(hPIPEOutRSVC==INVALID_HANDLE_VALUE){
                Fncs.Loguear("CLIENT: The Pipe Hasnt been started!");
                RsvStopFlag=true;
                return FALSE;
        }

        BOOL bWrite = false;
        DWORD BYTESWRITTEN = 0;

        char buffer[BlockSize+16];
        PipeRSV* SendPck=(PipeRSV*)&buffer;
        //copy string into buffer and fill with terminating null characters
        memcpy(SendPck->Sig,Sig,8);
        SendPck->BlockPos=BlockPos;
    SendPck->PckSize=(DWORD)Len;
        memcpy(SendPck->Data,Message,Len);
       
        if ( hPIPEOutRSVC != INVALID_HANDLE_VALUE ){
                //Write char array "buffer" to the pipe handle held in hPIPE
                bWrite = WriteFile( hPIPEOutRSVC, buffer, sizeof(buffer), &BYTESWRITTEN, NULL );

                if ( bWrite == FALSE ){
                        Fncs.Loguear("WriteFile() Error:",GetLastError());
                        RsvStopFlag=true; //we exit every thread
                }
                return bWrite;
        }else{
                Fncs.Loguear("CREATEFILE FAILED!",GetLastError());;
                RsvStopFlag=true;
                CloseHandle(hPIPEOutRSVC);
                return FALSE;
        }


}


BOOL StartPipeRSVC(){
        LPCTSTR _PIPE_NAME = "\\\\.\\pipe\\RSVHPipeIn";
        hPIPEOutRSVC = CreateFile(_PIPE_NAME, GENERIC_WRITE,0, NULL, OPEN_EXISTING,0, NULL);
        if(hPIPEOutRSVC==INVALID_HANDLE_VALUE){
                                       
                    char B[80];
                        sprintf(B, "Client:Pipe Coulnt Be Started: %d", GetLastError());
                        OutputDebugString(B);

                Fncs.Loguear("Client:Pipe Coulnt Be Started",GetLastError());
                RsvStopFlag=true;
                return FALSE;
        }else{
        return TRUE;
        }

Thx in advance

index position in array Issue

$
0
0
my program takes the values from one array and searches for their index position in another array(linear search algorithm).
this is an example of the issue im having(its not part of the actual code below)
a[]={1,2,3,4,5,6}
Arr[]={1,2,2,3,4,5}
if it finds 1 in arr, it returns 0, which is fine but if it finds 2 in arr it return 1 and 1 instead of 1 and 2. any thoughts on how to fix this?
Code:

for (int q=0; q=size2;q++)
{
  int rs=secfunc(array1;size1;array2[q])
  if(rs>=0)
  {
    cout<<rs << "\n";
  }
}

return 0;

int secfunc(int arr[],int SIZE, int values)
for (int a=0;a<SIZE;a++)
 {
  if(arr[a]==values)
  {
  return a;
  }
 }
return -1;
}

New Student Help

$
0
0
My professor asked us to trace this problem. I do not understand it. The first row is 23, 12, 5, 6. But when I run it through Dev++ compiler I do not understand the rest of the numbers. What is dont in this? Any help would be great. Thanks.
Function Trace Exercise
Consider the following program.
#include <iostream.h>
int a=1,b=1,i=1,j=1;
void dont(int & a, int & b){
i = 4 + a;
j = b + i;
b = a + i + j;
a = b + j + i;
}
int main (void) {
dont(a,b);
cout << a << " " << b << " " << i << " " << j << "\n";
a=1; b=1; i=1; j=1;
dont(i,j);
cout << a << " " << b << " " << i << " " << j << "\n";
a=1; b=1; i=1; j=1;
dont(j,i);
cout << a << " " << b << " " << i << " " << j << "\n";
a=1; b=1; i=1; j=1;
dont(a,i);
cout << a << " " << b << " " << i << " " << j << "\n";
return(0);
}
What outputs will be produced?

Need help with a structure

$
0
0
I'm trying to get the program to read from a file of 15 scores. 10 are quizzes 5 are exams. I want my program to read from the input file the first name "or" last name and if the user puts a different name, the program Gives off an error screen messege

code:
Code:

#include <iostream>
#include <fstream>
#include <string>
#include <cstdlib>
using namespace std;

const int NUM_STUDENTS = 20;
const int NUM_QUIZZES = 10;
const int NUM_EXAMS = 5;

struct student
{
      string firstName;
      string lastName;
      int quizzes[NUM_QUIZZES];
      int exams[NUM_EXAMS];
};



int main()
{
    student Evaluation[NUM_STUDENTS];
   
    ifstream inStream;
   
    inStream.open("C:/Users/Meelo/Desktop/infile.txt");
   
   
    for (int index = 0; index < NUM_STUDENTS; index++)
        {
                cout << "Enter student's first name: ";
                inStream >> Evaluation[index].firstName;
               
                cout << "Enter student's last name: ";
                inStream >> Evaluation[index].lastName;

                if(!inStream)
    {
      cout << "The name you have entered does not appear on the list" << endl;
}
}
    system("pause");
    return 0;
}

Visual C++ 6.0 for Notepad

$
0
0
hi,
I have a Visual C++ 6.0 program which automates excel and works with excel files.
Now I need to work with a text file.
I am wondering how I can open a Notepad file as an excel one, using my program.

If anyone can help please do

Thanks
Val

How to do clone in vc++?

$
0
0
It's possible in c#, looks like.

need help with timer in CDoument

How to use Visual Studio 2010 to compile dos programs?

$
0
0
I want to use it to compile 16bit dos programs
and 32bit protected mode programs
Thanks
Jack

help me with data structure

$
0
0
hi i want some help with programing code in data structures

i have algorithm for bubble sort

bubblesort(inta[],int size)

Please help me program in c language

$
0
0
help me do this in C language.. please :( i really need it ASAP

4.1 Write a program that will count from 1 to 12 and print the count, and its square, for each count.


4.2 Write a program that counts from 1 to 12 and prints the count and its inversion to 5 decimal places for each count. This will require a floating point number.


4.3 Write a program that will count from 1 to 100 and print only those values between 32 and 39, one to a line. Use the incrementing operator for this program.

Compiler / linker flags

$
0
0
I'm helping a friend to modify a waf script for a program which was originally intended to be compiled with gcc/mingw. He's trying to adapt it to be buildable with MSVC. The script contains a table of flags which get sent to the compiler or linker. Fortunately, each entry contains a good description of what it gets used for:-

Code:

    'gcc' : {
        # Flags required when building a debug build
        'debuggable' : [ '-O0', '-g' ],

        # Flags required for the linker (if any) when building a debug build
        'linker-debuggable' : '',

        # Flags required when building a non-debug optimized build
        'nondebuggable' : '-DNDEBUG',

        # Flags required to enable profiling at runtime
        'profile' : '-pg',

        # Flags required to disable warnings about unused arguments to function calls
        'silence-unused-arguments' : '',

        # Flags required to use SSE unit for general math
        'sse' : '-msse',

        # Flags required to use SSE unit for floating point math
        'fpmath-sse' : '-mfpmath=sse',

        # Flags required to use XMM Intrinsics
        'xmmintrinsics' : '-DUSE_XMMINTRIN',

        # Flags to use posix pipes between compiler stages
        'pipe' : '-pipe',

        # Flags for maximally optimized build
        'full-optimization' : [ '-O3', '-fomit-frame-pointer', '-ffast-math', '-fstrength-reduce', ],

        # Flag to ensure that compiler error output includes column/line numbers
        'show-column' : '-fshow-column',

        # Flags required to build for x86 only (OS X feature)
        'generic-x86' : '',

        # Flags required to build for PowerPC only (OS X feature)
        'generic-ppc' : '',

        # All flags required to get basic warnings to be generated by the compiler
        'basic-warnings' : [ '-Wall', '-Wpointer-arith', '-Wcast-qual', '-Wcast-align', '-Wno-unused-parameter' ],

        # Any additional flags for warnings that are specific to C (not C++)
        'extra-c-warnings' : [ '-Wstrict-prototypes', '-Wmissing-prototypes' ],

        # Any additional flags for warnings that are specific to C++ (not C)
        'extra-cxx-warnings' : [ '-Woverloaded-virtual', '-Wno-unused-local-typedefs' ],

        # Flags used for "strict" compilation, C and C++ (i.e. compiler will warn about language issues)
        'strict' : ['-Wall', '-Wcast-align', '-Wextra', '-Wwrite-strings', '-Wunsafe-loop-optimizations', '-Wlogical-op' ],

        # Flags used for "strict" compilation, C only (i.e. compiler will warn about language issues)
        'c-strict' : ['-std=c99', '-pedantic', '-Wshadow'],

        # Flags used for "strict" compilation, C++ only (i.e. compiler will warn about language issues)
        'cxx-strict' : [ '-ansi', '-Wnon-virtual-dtor', '-Woverloaded-virtual', '-fstrict-overflow' ],

        # Flags required for whatever consider the strictest possible compilation
        'ultra-strict' : ['-Wredundant-decls', '-Wstrict-prototypes', '-Wmissing-prototypes'],

        # Flag to turn on C99 compliance by itself
        'c99': '-std=c99',
    },

We'll need a similar table to send to MSVC - something like:-

Code:

  'msvc' : {
        'debuggable' : ['/D DEBUG'],
        'linker-debuggable' : ['/DEBUG' ],
        'nondebuggable' : [ '/D NDEBUG' ],
        'profile' : '',
        'silence-unused-arguments' : '',
        'sse' : '',
        'fpmath-see' : '',
        'xmmintrinsics' : '',
        'pipe' : '',
        'full-optimization' : '',
        'show-column' : '',
        'generic-x86' : '',
        'generic-ppc' : '',
        'basic-warnings' : '',
        'extra-c-warnings' : '',
        'extra-cxx-warnings' : '',
        'strict' : '',
        'c-strict' : '',
        'cxx-strict' : '',
        'ultra-strict' : '',
        'c99' : '',
    },

I realise that many of the other options won't have any equivalent in MSVC - but can anyone suggest any of the ones which do? Or is there a good list of MSVC compiler & linker flags somewhere?

[RESOLVED] HELP : converting a decimal number given by the user to binary using C++

$
0
0
Write a C++ program that adds three binary numbers of 8-bit
each. Every number is stored into an array of 8 elements.
Example:

Array A
0 1 2 3 4 5 6 7
0 1 1 0 1 1 1 0
+
Array B
0 1 2 3 4 5 6 7
0 1 1 0 1 1 1 0
+
Array C
0 1 2 3 4 5 6 7
0 1 1 0 1 1 1 0

Store the result into an array D of 8 elements. Your program
should show the decimal numbers for every binary number.
Print screen of 6 answers. This means you should try your
program six times with different numbers in every run and show
the printed screen result.
could you guys help me with this exercise

Help with IADsUser::Put when calling setInfo(), error E_ADS_INVALID_USER_OBJECT

$
0
0
Hello, I am looking for a solution that may be very simple but I can't find it, I am a beginner.

I am trying to call the setInfo() function, when committing changes to a user object in Active Directory after using Put(). The call results in E_ADS_INVALID_USER_OBJECT error. I am able to bind with LDAP successfully, my code is:

Code:

IADsUser *pUser = NULL;
RESULT hr = CoInitialize(0);
VARIANT var;
hr = ADsGetObject(L"LDAP://CN=Foo Bar,CN=Users,DC=mydomain,DC=com", IID_IADsUser, (void**) &pUser);
VariantInit(&var);
V_BSTR(&var) = SysAllocString(L"foobar@email.com");
V_VT(&var) = VT_BSTR;
hr = pUser->Put(CComBSTR("mail"), var);
hr = pUser->SetInfo(); //ERROR: E_ADS_INVALID_USER_OBJECT

The Get() function works and I am able to retrieve user information. The above code runs in a DLL by a process which is run by the Local System account. Does the Local System have enough permissions to make changes in AD objects? Can I give Local System more permissions? If I run the same code in an executable, it works I can't figure it out..

Tips are very appreciated. Thanks!

Recursion involving tree with many branches and all branches need to be stored

$
0
0
I want to store all the result which are basically 8 points generated after every time function
GenTestPoint is called.

Can you suggest me how to store all the points generated i.e 4096+512+64+8 points. However, I mainly need the 4096 points which are generated at the end. I am new to programming, not much familiar with pointer and all stuff.

Its start from level 1.

Level 1 = 8 Points;
Level 2 = 64 points;
Level 3 = 512 Points;
Level 4 = 4096 points;
8 points will be calculated only when if statement is true. But it's fine in the worst case all the statements are true and at the end we will get 4096 points. Just consider that all the if statements are true and I am getting 4096 points at the end which I need to store in some GLOBAL Variable.

I need this 4096 points at the end, but even if you can suggest me to store all the points at the end, then also its good.

void GenTestPoint(Vec3f test, float level)
{

float new_denominator = pow(2.0f,level);
Vec3f result1, result2, result3, result4, result5, result6, result7, result8;
Vec3f result11, result12, result13, result14, result15, result16, result17, result18;

result1 = (test.x - 1/new_denominator, test.y - 1/new_denominator, test.z - 1/new_denominator);

result2 = (test.x - 1/new_denominator, test.y - 1/new_denominator, test.z + 1/new_denominator);

result3 = (test.x + 1/new_denominator, test.y - 1/new_denominator, test.z + 1/new_denominator);

result4 = (test.x + 1/new_denominator, test.y - 1/new_denominator, test.z - 1/new_denominator);

result5 = (test.x + 1/new_denominator, test.y + 1/new_denominator, test.z - 1/new_denominator);

result6 = (test.x - 1/new_denominator, test.y + 1/new_denominator, test.z - 1/new_denominator);

result7 = (test.x - 1/new_denominator, test.y + 1/new_denominator, test.z + 1/new_denominator);

result8 = (test.x + 1/new_denominator, test.y + 1/new_denominator, test.z + 1/new_denominator);

while (level < 5)
{
if (CheckInOut(result1)= true)
GenTestPoint(result1, level);
else
break;

if (CheckInOut(result2)= true)
GenTestPoint(result2, level);
else
break;

if (CheckInOut(result3) = true)
GenTestPoint(result3, level);
else
break;
if (CheckInOut(result4)= true)
GenTestPoint(result4, level);
else
break;

if (CheckInOut(result5)= true)
GenTestPoint(result5, level);
else
break;

if (CheckInOut(result6)= true)
GenTestPoint(result6, level);
else
break;

if (CheckInOut(result7)= true)
GenTestPoint(result7, level);
else
break;

if (CheckInOut(result8)= true)
GenTestPoint(result8, level);
else
break;
level = level + 1;
}


}

Joystick data retrieval and UDP socketing

$
0
0
Hi,
Im new to CG forum so i want to be as polite and descriptive as possible. :wave:

I want a simple c++ code that, first retrieves a joystick data (say PS3) and then sends the data to an IP address for further execution. Im using Arduino board on the receiver side,and i set it up so that it receives data from a specific port. I have tried sending simple LED on/off data from puTTy and it worked perfectly but now i want to do it in C++ project because puTTy doesnt obviously allow you to capture joystick data (its only input it when you type the data to be sent by yourself). There is a solution file im trying to use but somehow after it successfully shows me that it is receiving the joystick data, it doesnt send it to the specified IP address, thus nothing happens on arduino. Im linking the Code im using below soplease anyone just tell me where im going wrong. Thanx in advance !

http://www.instructables.com/files/o...7AHJKBW2EB.zip

Joystick data retrieval and UDP socketing

$
0
0
Hi,
Im new to CG forum so i want to be as polite and descriptive as possible. :wave:

I want a simple c++ code that, first retrieves a joystick data (say PS3) and then sends the data to an IP address for further execution. Im using Arduino board on the receiver side,and i set it up so that it receives data from a specific port. I have tried sending simple LED on/off data from puTTy and it worked perfectly but now i want to do it in C++ project because puTTy doesnt obviously allow you to capture joystick data (its only input it when you type the data to be sent by yourself). There is a solution file im trying to use but somehow after it successfully shows me that it is receiving the joystick data, it doesnt send it to the specified IP address, thus nothing happens on arduino. Im linking the Code im using below soplease anyone just tell me where im going wrong. Thanx in advance !

[url]http://www.instructables.com/files/orig/FOP/QL7A/HJKBW2EB/FOPQL7AHJKBW2EB.zip

Matrix multiply c++

$
0
0
Hello all
I'm a newbie in C++... Could you please help me solve this calculation with C++: I have two matrix in two text files:

File A:

10001 14462 14382 14459
10002 14304 14382 14462
10003 14298 14382 14304
10004 14459 14382 14298
10005 14473 14386 14462
File B:

1446 2 1 5
14382 5 9 8
14459 6 9 5
14304 5 2 1
14462 7 5 4
14298 5 4 7
14473 2 3 4
we have A11=1001; A21=1002...and I want to create a new matrix

AA=
10001 (v14462-v14382) (v14382-v14459) (v14459-v14462)
10002 (v14304-v14382) (v14382-v14462) (v14462-V14304)
10003 ...............................................
10004 ...............................................
10005 ...............................................
where v14462 is a vector which could get from file B, it means vector v14462=[2 1 5]; same for v14382, v14459.....

Thank you all very much! Happy christmas and happy new year!
Viewing all 3020 articles
Browse latest View live