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

Need Help

$
0
0
My question is how would i write my code to allow only m=male to appear only not the f=female. I'm sorry if thats too much to ask i just started learning so im sorry if i am a beginner. Here is the text file that says all the details:
Josheph 1985 $10000 m
Nina 1998 $5000 f
Mark 1990 $20000 m
Katlyn 1989 $50000 f
Joe 1967 $90000 m
Nick 1970 $70000 m
Rose 1980 $10000 f
Alice 1965 $200000 f
Emmett 1978 $50000 m
Charlie 1969 $54000 m
Jessica 1992 $199999 f

And this is my code so far, im trying to change and add stuff to debug the code but it does not print only male details prints out everything. I looked all over google to find out how to do it but i cant seem to find one.

Code:

#include <iostream>
#include <fstream>
#include <string>

using namespace std;

int main()
{
        string name;
        string birthyear;
        string salary;
        string sex;
        char gender;
       

        ifstream file;
        file.open("example.txt");

        cout << "\nEnter m for males or f for females to choose" << endl;
        cin >> gender;
        cin.get();
        if (gender == 'm'){
                while (file >> name >> birthyear >> salary>>sex){
                        cout << name << ' ' << birthyear << ' ' << salary << ' ' << sex << endl;
                }

        }

        cin.get();
        return 0;
}


Question about this website

$
0
0
is it possible to delete one of my older threads ? jus wondering...

Help me with this code please

$
0
0
:wave:



I made this code
Code:

#include <iostream>
using namespace std;
 
void Cloud(int[], int);
 
int main()
{
 int i;
    int Rain[5];
       
       
        for (i=0;i<=4;i++){
        cout<<"please input"<<endl;
        cin>>Rain[i];
       
       
        }
    Cloud(Rain, 5);

       
 system ("pause");
}

void Cloud( int array[], int size)
{int i,j,temp;

        array[5];

    for(int i = 0; i <size-1; i++)
    {
                for(j=i+1;j<=size-1;j++)
                {
                        if(array[i]<array[j])
                        {
                        temp=array[i];
                        array[i]=array[j];
                        array[j]=temp;
                       
                        }
    }
}
        for(i=0;i<=size-1;i++){
        cout <<endl<<array[i]<<endl;
        }
}


but I need to stop the input when the user types a character using this type of while loop. I tried many types to include this loop in my program but it doesn't work. :cry: thanks for your help
Code:

cout<<"Please insert a number: ";
        while (! ( cin >> y))
    {
      cin.clear ();
      cin.ignore (1000000,'\n');
   
      cout<<"Insert a number: ";
    }
    cout<<"The number you typed is: "<< y << "\n\n";

[RESOLVED] Closest distance between two line segments

$
0
0
Does anyone know a good algorithm for calculating the closest points/distance between two line segments? I use some pretty general code:

http://geomalgorithms.com/a07-_distance.html

which seems widely used and advertized on the web and works in most cases but seems to often fail horribly when line segments are nearly parallel. I've been messing with the SMALL_NUM value for division overflow to no avail. The calculated distance can still vary widely when nearly parallel.

I managed to isolate a specific incident where this happens in my code. The distance between segments P1P2 and Q1Q2 changed abruptly in one timestep from 1.05 mm to 0.90 mm (yarn radius = 1 mm), causing abrupt compression spikes. In reality the distance in the original timestep is definitely also around 0.90 mm but is not calculated as such. I find that the values of s and t (s=0 for P1, 1 for P2, t=0 for Q1, 1 for Q2) for the closest points are originally 0 and 0 (as well as in the previous time steps) and then change abruptly to 0 and around 0.29 in the new time step. What it should be, I still need to check out.

P1 = (0.012711 ,-0.000688 ,-0.001097);
P2 = (0.012895 ,-0.000686 ,-0.001133);
Q1 = (0.012676 ,-0.000689 ,-0.000999);
Q2 = (0.012859 ,-0.000687 ,-0.001034);

P1new = (0.012712, -0.000689, -0.001095);
P2new = (0.012895, -0.000687, -0.001131);
Q1new = (0.012676, -0.000690, -0.000996);
Q2new = (0.012859, -0.000688, -0.001032);

Results when calculating self contact of 15000 line segments in a few tens of fibers, one big mess:



Anyone know of a better algorithm/corrections?

Get active url in Google Chrome from v.29 with IAccessible

$
0
0
Based in some examples of source codes as this => http://stackoverflow.com/questions/2...urrent-version, I'm trying get active url on address bar from Google Chrome with IAccessible, but it always return NULL (0). Could someone help me please?

Any suggestion will be welcome.

Here is my last attempt:

Code:


#include "stdafx.h"
#include <Windows.h>
#include <Oleacc.h>
#pragma comment( lib,"Oleacc.lib")

HWINEVENTHOOK LHook = 0;

void CALLBACK WinEventProc(HWINEVENTHOOK hWinEventHook, DWORD event, HWND hwnd, LONG idObject, LONG idChild, DWORD dwEventThread, DWORD dwmsEventTime) {

    IAccessible* pAcc = NULL;
    VARIANT varChild;
    HRESULT hr = AccessibleObjectFromEvent(hwnd, idObject, idChild, &pAcc, &varChild);

    if ((hr == S_OK) && (pAcc != NULL)) {
        BSTR bstrValue;
        pAcc->get_accValue(varChild, &bstrValue);

        char className[500];
        GetClassName(hwnd, (LPWSTR)className, 500);

        if (event == EVENT_OBJECT_VALUECHANGE){

            /*

          Window classe name of each browser =>

            Safari => SafariTaskbarTabWindow
            Chrome => Chrome_WidgetWin_1
            IE => IEFrame
            Firefox => MozillaWindowClass
            Opera => OperaWindowClass

            */

            if (strcmp(className, "Chrome_WidgetWin_1") != 0) {
                printf("Active URL: %ls\n", bstrValue);
            }
        }
        SysFreeString(bstrValue);
        pAcc->Release();
    }
}

void Hook() {

    if (LHook != 0) return;
    CoInitialize(NULL);
    LHook = SetWinEventHook(EVENT_OBJECT_FOCUS, EVENT_OBJECT_VALUECHANGE, 0, WinEventProc, 0, 0, WINEVENT_OUTOFCONTEXT | WINEVENT_SKIPOWNPROCESS);
}

void Unhook() {

    if (LHook == 0) return;
    UnhookWinEvent(LHook);
    CoUninitialize();
}


int main(int argc, const char* argv[]) {

    MSG msg;
    Hook();

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

    Unhook();

    return 0;
}

[RESOLVED] Get active url in Google Chrome from v.29 with IAccessible

$
0
0
Based in some examples of source codes as this => http://stackoverflow.com/questions/2...urrent-version, I'm trying get active url on address bar from Google Chrome with IAccessible, but it always return NULL (0). Could someone help me please?

Any suggestion will be welcome.

Here is my last attempt:

Code:


#include "stdafx.h"
#include <Windows.h>
#include <Oleacc.h>
#pragma comment( lib,"Oleacc.lib")

HWINEVENTHOOK LHook = 0;

void CALLBACK WinEventProc(HWINEVENTHOOK hWinEventHook, DWORD event, HWND hwnd, LONG idObject, LONG idChild, DWORD dwEventThread, DWORD dwmsEventTime) {

    IAccessible* pAcc = NULL;
    VARIANT varChild;
    HRESULT hr = AccessibleObjectFromEvent(hwnd, idObject, idChild, &pAcc, &varChild);

    if ((hr == S_OK) && (pAcc != NULL)) {
        BSTR bstrValue;
        pAcc->get_accValue(varChild, &bstrValue);

        char className[500];
        GetClassName(hwnd, (LPWSTR)className, 500);

        if (event == EVENT_OBJECT_VALUECHANGE){

            /*

          Window classe name of each browser =>

            Safari => SafariTaskbarTabWindow
            Chrome => Chrome_WidgetWin_1
            IE => IEFrame
            Firefox => MozillaWindowClass
            Opera => OperaWindowClass

            */

            if (strcmp(className, "Chrome_WidgetWin_1") != 0) {
                printf("Active URL: %ls\n", bstrValue);
            }
        }
        SysFreeString(bstrValue);
        pAcc->Release();
    }
}

void Hook() {

    if (LHook != 0) return;
    CoInitialize(NULL);
    LHook = SetWinEventHook(EVENT_OBJECT_FOCUS, EVENT_OBJECT_VALUECHANGE, 0, WinEventProc, 0, 0, WINEVENT_OUTOFCONTEXT | WINEVENT_SKIPOWNPROCESS);
}

void Unhook() {

    if (LHook == 0) return;
    UnhookWinEvent(LHook);
    CoUninitialize();
}


int main(int argc, const char* argv[]) {

    MSG msg;
    Hook();

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

    Unhook();

    return 0;
}

Data structure for text predictor using qwerty keyboard in c++

$
0
0
Hello guyz i m new, i got project to make a program of text predictor. i know the concepts of c++. array, classes , recursion, in data structure linked list, stack, queues and trees etc.. but i still need help to make fast and efficient program of text predictor.
i got data in file.txt , in fact it is a dictionary data.....
Thanx in advance....::

Showing console Windows in a Win 32 DLL

$
0
0
Is it possible to show a console window in a Win32 DLL?

My program doesn't accept my input values true, although they are

$
0
0
I am making a program which is going to print out a head image according to the input values entered by the user. Here is the code:

Code:

#include <iostream>
    #include <string>

    using namespace std;

    void Sides()
    // draws the sides to take proportion
    {
              cout << "|                |" << endl;
    }
    void Hair()
    // draws a bald hair
    {
            cout << "__________________" << endl;
    }
    void Hair2()
    // draws a parted hair
    {
            cout << "|||||||||/////////" << endl;
    }
    void Eyes()
    //draws angry eyes
    {
            cout<< "|  ---      ---  |" << endl;
    }
    void Nose()
    //draws a normal nose
    {
            cout<< "|        o        |" << endl;
    }
    void Mouth()
    //draws an angry mouth
    {
            cout<< "|      ____      |" << endl;
    }
    void Mouth2()
    //draws a happy mouth
    {
            cout<< "|    |_____|      " << endl;
    }
    void Head1()
    //draws a face with a bald head and an angry mouth
    {
            Hair();
            Sides();
            Eyes();
            Sides();
            Nose();
            Sides();
            Mouth();
    }
    void Head2()
    //draws a face with parted hair and an angry mouth
    {
            Hair2();
            Sides();
            Eyes();
            Sides();
            Nose();
            Sides();
            Mouth();
    }
    void Head3()
    //draws a face with a bald head and a happy mouth
    {
            Hair();
            Sides();
            Eyes();
            Sides();
            Nose();
            Sides();
            Mouth2();
    }
    void Head4()
    //draws a face with parted hair and a happy mouth
    {
            Hair2();
            Sides();
            Eyes();
            Sides();
            Nose();
            Sides();
            Mouth2();
    }

    int main ()
    {
            string headstyle, mouthstyle;

            cout << "plase enter which way you want to print out the head, with parted hair or bald." <<      endl;
       
       
            if (cin >> headstyle != "bald" || cin >> headstyle != "parted hair" )
            {
                            cout << "wrong input" << endl;
            }

            else
            {
                    cout << "plase enter which way you want to print out the motuth, happy or angry." << endl;
               
                    if (cin >> mouthstyle != "happy" || cin >> mouthstyle != "angry")
                    {
                            cout << "wrong input" << endl;
                    }
                    else if (headstyle == "bald" && mouthstyle == "angry")
                    {
                            Head1();
                    }
                    else if (headstyle == "parted hair" && mouthstyle == "angry")
                    {
                            Head2();
                    }
                    else if (headstyle == "bald" && mouthstyle == "happy")
                    {
                        Head3();
                    }
                    else if (headstyle == "parted hair" && mouthstyle == "happy")
                    {
                            Head4();
                    }
       
       
       
            }
       
            cin.ignore();
            cin.get();
            return 0;
    }

at first i tried to work program like:

Code:

  cout << "plase enter which way you want to print out the head, with parted hair or bald." << endl;
                cin >> headstyle;
       
                if (headstyle != "bald" || headstyle != "parted hair" )


but it also had given the same mistake. The program compiles BUT; even if I put in the values bald or parted hair the program prints out "wrong input" then exits. If you could help, I'd be really grateful.

error : string subscript out of range

$
0
0
Hello guys i have a quick question
I have an assignment where i have to prompt the user to enter the name of a file
then open that file and read names of students and what level they are at university
eg : John Wilkins, sophomore
Dan Robertson, junior
etc..

i did the code and it compiles perfectly, but when i input the name of the file it gives me error: string subscript out of range.
here's the code:

Code:

#include <iostream>
#include <cstring>
#include <string>
#include<ctime>
#include <fstream>
using namespace std;

int *  read_file(string filename)
{
        enum year_classification{ freshman, sophomore, junior, senior, graduate};
        int count[5], i;
        for (int j=freshman; j<=graduate; j++)
                count[j]=0;
        string word;
        ifstream infile;
        infile.open(filename.c_str());
        if ( infile.is_open() )
        {
                while( !infile.eof() )
                {
                        getline(infile,word);
                        i=0;
                        while (word[i] != ',')
                        {
                                i++;
                        }
                        switch ( word[i+2] )
                        {
                                case 'g': count [graduate] ++;
                                                        break;
                                case 'j': count [junior] ++;
                                                        break;
                                case 'f': count [freshman] ++;
                                                        break;
                                case 's': {if( word[i+2] = 'o') count [sophomore]++; else count [senior]++;
                                                        break;}
                        }
                }
        }
        else cout<<"could not open file"<<endl;
        return count;
}




int main()
{
        enum year_classification{ freshman, sophomore, junior, senior, graduate};
        string filename;
        cout<<"Please enter the name of the file : ";
        getline(cin,filename);
        cout<<"Number of graduate : "<<read_file(filename)[graduate]<<endl;
        cout<<"Number of senior  : "<<read_file(filename)[senior]<<endl;
        cout<<"Number of sophomore: "<<read_file(filename)[sophomore]<<endl;
        cout<<"Number of junior  : "<<read_file(filename)[junior]<<endl;
    cout<<"Number of freshman : "<<read_file(filename)[freshman]<<endl;
        return 0;
}

Close CPropertySheet from another CPropertySheet's PropertyPage

$
0
0
Hi,

I was opened CPropertySheet from main dialog at very first time, again i was opened the CPropertySheet from current PropertySheet's Page 1 using button click event.

How can i close these two sheets and go to main dialog.

I was used EndDialog(0);

Which goes to previous sheet only.

Visual Studio 2013 Crash Problem.

$
0
0
Recently Visual Studio 2013 has pretty much stopped working for me. Every time I hit the debug run button the program crashes and gives me the following information.

Code:

Problem signature:
  Problem Event Name:        BEX
  Application Name:        devenv.exe
  Application Version:        12.0.30723.0
  Application Timestamp:        53cf6f00
  Fault Module Name:        MSVCR120.dll
  Fault Module Version:        12.0.21005.1
  Fault Module Timestamp:        524f7ce6
  Exception Offset:        000a46bb
  Exception Code:        c0000417
  Exception Data:        00000000
  OS Version:        6.1.7601.2.1.0.256.48
  Locale ID:        1033
  Additional Information 1:        0f4c
  Additional Information 2:        0f4cc2e35047e82f90416abcbb686e57
  Additional Information 3:        8f08
  Additional Information 4:        8f080078d8638d40bf20c125c9cc2499

I have tried reinstalling Visual Studio. I have searched on the internet and not found how to stop this problem from happening. This happens with all my projects/solutions. Previously this worked fine.

[RESOLVED] Close CPropertySheet from another CPropertySheet's PropertyPage

$
0
0
Hi,

I was opened CPropertySheet from main dialog at very first time, again i was opened the CPropertySheet from current PropertySheet's Page 1 using button click event.

How can i close these two sheets and go to main dialog.

I was used EndDialog(0);

Which goes to previous sheet only.

read an excel file with c++ and storage in an array

$
0
0
Hi everyone,
I wish to read an excel file which contains the table shown at the picture below.
I don't really know how to code the direct storage of the values in the appropriate array.
For example I wish to store the countries in an array of a string type.
Please could I have some piece of code which illustrates it (I mean the reading of an excel file and the direct storage of his value in an array).
Thank you

Name:  titres.png
Views: 73
Size:  30.5 KB
Attached Images
 

please help me correct this code

$
0
0
I made this code
Code:

#include <iostream>
#include <iomanip>
using namespace std;

const int ro=5;
const int col=5;

void multi(int mb[ro][col])
{
for (int i = 1; i < ro; i++) {
mb[0][i] = i;
}

for (int i = 1; i < ro; i++){
mb[i][0] = i;

for (int j = 1; j < col; j++)
mb[i][j] = i * j;
}
}

int main()
{
        int mb[ro][col] ={};

multi(mb);


for (int i = 0; i < ro; i++) {

       
for (int j = 0; j < col; j++) {

cout << "  " << setw(4) << mb[i][j];

}
cout << endl;
}
system("pause");
return 0;

}

it outputs a 5x5 multiplication table...the thing is the professor wants us to use global variables for the array as well
so i think the code would look something like this
Code:

#include <iostream>
#include <iomanip>
using namespace std;

const int ro=5;
const int col=5;
int mb[ro][col];

void multi()
{
for (int i = 0; i < 5; i++) {
       
for (int j = 0; j < 5; j++){

        mb[ro][col]= i * j;


}
}
}


int main()
{


multi();


for (int i = 0; i < 5; i++) {

       
for (int j = 0; j < 5; j++) {

cout << "  " << setw(4) << mb[ro][col];

}
cout << endl;
}
system("pause");
return 0;

}

the thing is i only get 16's :D I know I'm missing something but i can't see it .thanks :)

arrays inside functions. can not get an errorless program!!

$
0
0
please help!!!

hello i have been trying to construct a program for about a week now and im having no luck. i have tried many different things and now i am stuck. (im not looking for someone to write the program for but to help me get going because im totally lost at this point)
here is what i got so far:

#include <iostream>
#include <algorithm>
using namespace std;

void help(void);
void smallest(void);
double findSmallest(double s[], int& f, int size);
double sizeOfArray(void);
double getInputs(void);
void display(double array[], double ss, int& freq, int size);
void largest(void);
double findLargest(double s[], int& f, int size);

int main()
{
char menu;
int flag =1;
while(flag == 1)
{

cout << "Help Smallest Largest Quit\n:";
cin >> menu;

switch(menu)
{
case 'h':
case 'H':
help();
break;
case 's':
case 'S':
smallest();
break;
case 'l':
case 'L':
break;
case 'q':
case 'Q':
flag = 0;
cout << "program terminated upon user request\n";
break;
default:
cout << "Wrong choice\n\nPlease make another selection\n";
}
}
return 0;
}

void help(void)
{
cout <<"if the user selects s the program will take the smallest of the numbers entered";
cout <<"if the user selects l the program will take the largest of the numbers entered";
cout <<"if q is chosen the program will quit\n";

return;
}

void smallest(void)
{
cout << "how many values: " << flush;
int size = sizeOfArray();
double values[size];
for ( int i = 0; i < size; ++i)
{
values[i] = getInputs();
}
int frequency = 0;
double smallest = findSmallest(values, frequency, size);
display(values,smallest,frequency,size);
cout << "strike any key to continue";
char ch;
cin >> ch;
}

double sizeOfArray(void)
{
double size;
return size;
}

double getInputs(void)
{
double k;
cout << "input values to be evaluated";
cin >> k;
return k;

}

double findSmallest(double s[], int& f, int size)
{
int smallest;

return smallest;
}

void display(double array[], double ss, int& freq, int size)
{

}

void largest(void)
{

}

double findLargest(double s[], int& f, int size)
{
int largest;

return largest;
}


and here is what is being asked by the teacher:

Upon program execution, the screen will be cleared and the menu shown above will appear at the top of the screen and centered. The menu items are explained below.
Help Smallest Largest Quit
H or h ( for Help ) option will invoke a function named help() which will display a help screen. The help screen(s) should guide the user how to interact with the program, type of data to be entered, and what results would the program produce. Each help screen should remain on the monitor until the user strikes any key. Once the user's input is processed, the screen will be cleared and the menu is displayed again.
S or s ( for Smallest ) option will invoke a function named smallest( ) which will prompt the user for the number of elements of an array of type double to be examined. The program will use a function named sizeOfArray( ), which will read the keyboard, and then returns the number of elements, followed by another prompt to get the actual elements, using the function getInputs( ). The program will then call a function named findSmallest( ) which will compute and return the smallest number in the array, and its frequency of occurrence. The program will then display the array elements, the smallest number, and its frequency of occurrence using a function named display( ), in the format shown below, in the middle of the screen. The output shown is for an array of six elements with an array identifier a. Your array will be different.
a[0] = xxxx.xx
a[1] = xxxx.xx
a[2] = xxxx.xx
a[3] = xxxx.xx
a[4] = xxxx.xx
a[5] = xxxx.xx
Smallest no. = xxxx.xx Frequency = xx
The function prototypes to be used are as follows:
void smallest(void);
double findSmallest(double s[], int& f, int size);
here, s is the array, f is the frequency of occurrence, and size is the current size of the array.
int sizeOfArray(void);
double getInputs(void);
void display(double array[], double ss, int& freq);
The results should stay on the screen with the following prompt which will appear on the lower right hand corner of the screen:
Strike any key to continue...


the second half is exactly the same but to find the largest value. (note i already have the largest function prototypes in the program)

Structures function - can someone complete this code

$
0
0
I'm writing a function that compares two fraction. if the fractions are equal it returns 0. If the fraction in the first parameter is less than the fraction in the second parameter it returns a negative number. Otherwise it returns a positive number. in doing so convert the fraction to a floating point number.

Im stuck need help completing the function to run


typedef struct fracion
{
int numo;
int denom;
}fraction;

int compareFractions (fracion, fraction);

void main()
{
int x;
fraction f1, f2;
printf("Enter Numo and Demo");
scanf_s("%d%d", &f1.numo, &f1.denom);
printf("Enter Numo and Demo");
scanf_s("%d%d", &f2.numo, &f2.denom);

x = compareFractions(f1, f2);
}

int compareFractions(fraction frac1, fraction frac2)
{
float conf1;
float conf2;

conf1 = frac1.numo / frac1.denom;
conf1 = frac2.numo / frac2.denom;



}

ATL COM DLL - include an object from another ATL COM DLL

$
0
0
Hello team,
this refers to an ATL COM DLL project. I can successfully create a class hierarchy of objects, ie. say, one class is the TEAM, which then holds other objects, say, a leader and a secretary, both of which are Employee Classes (this is inspired by Richard Grimes Beginning ATL3 COM Programming, chapter 9 "Developer Collection". For sake of simplicity, in my case I need not address the complexities of the collection subject)
Here goes my question:

a) In the Team.h header file I declare m_pLeader as a CComPtr<IEmployee>

Code:

classATL_NO_VTABLE CTeam :
        public CComObjectRootEx<CComSingleThreadModel>,
        public CComCoClass<CTeam, &CLSID_Team>,
public IDispatchImpl<ITeam, &IID_ITeam, &LIBID_BUOBJ05Lib, /*wMajor =*/ 1, /*wMinor =*/ 0>
{
private:
        CComPtr<IEmployee> m_pLeader;
        CComPtr<IEmployee> m_pSecretary;

b) The Employee Class is defined within this ATL COM project.
c) In the Team.cpp file, I create an instance in the FinalConstruct code, the focus is on the CEmployee

Code:

HRESULT CTeam::FinalConstruct(){
        CComObject<CEmployee>* pLeader;
        HRESULT hr=CComObject<CEmployee>::CreateInstance(&pLeader);
        if (FAILED(hr))
                        return hr;
        m_pLeader=pLeader;
// ..same for secretary...
return S_OK
}

d) Here comes my QUESTION: How must I proceed if the Employee object was part of another ATL COM DLL, that is it would be described in another DLL that I would now like to reuse?
I guess I need to
1. Have the other DLL's idl-, tlb, and h file in my project folder. Let me name it "other.h, other.idl, other.tlb"
2. Both h- and cpp-file must have an #include "other.h" statement -- please correct if I am wrong..
3. ...but how must in the Team's h- and cpp-files the statements be (assuming the class in the "other" Dll is Member (instead of Employee? I know the following code will NOT work, so I am asking how it should be correctly?

Code:

private:
        CComPtr<IMember> m_pLeader;

4. and in cpp file for:
Code:

        CComObject<CMember>* pLeader;
        HRESULT hr=CComObject<CMember>::CreateInstance(&pLeader);

[/code]

Your assistance would be appreciated!

Directx11 CreateTextFormat acess violation reading location 0x000000

$
0
0
Hello all,I downloaded an exemple on http://www.braynzarsoft.net/index.ph...stancing#still,apparently I am the only one to have an error at:
hr=DWriteFactory->CreateTextFormat(L"Script",NULL,DWRITE_FONT_WEIGHT_REGULAR,DWRITE_FONT_STYLE_NORMAL,DWRITE_FONT_STRETCH_NORMAL,50.0f,L"en-us",&TextFormat);

This is a small part of the source.
Code:

bool InitD2D_D3D101_DWrite(IDXGIAdapter1 *Adapter)
{
//Create our Direc3D 10.1 Device///////////////////////////////////////////////////////////////////////////////////////
        hr = D3D10CreateDevice1(Adapter, D3D10_DRIVER_TYPE_HARDWARE, NULL,D3D10_CREATE_DEVICE_BGRA_SUPPORT,
                D3D10_FEATURE_LEVEL_9_3, D3D10_1_SDK_VERSION, &d3d101Device        );       

        //Create Shared Texture that Direct3D 10.1 will render on//////////////////////////////////////////////////////////////
        D3D11_TEXTURE2D_DESC sharedTexDesc;       

        ZeroMemory(&sharedTexDesc, sizeof(sharedTexDesc));

        sharedTexDesc.Width = Width;
        sharedTexDesc.Height = Height;       
        sharedTexDesc.Format = DXGI_FORMAT_B8G8R8A8_UNORM;
        sharedTexDesc.MipLevels = 1;       
        sharedTexDesc.ArraySize = 1;
        sharedTexDesc.SampleDesc.Count = 1;
        sharedTexDesc.Usage = D3D11_USAGE_DEFAULT;
        sharedTexDesc.BindFlags = D3D11_BIND_SHADER_RESOURCE | D3D11_BIND_RENDER_TARGET;       
        sharedTexDesc.MiscFlags = D3D11_RESOURCE_MISC_SHARED_KEYEDMUTEX;       

        hr = d3d11Device->CreateTexture2D(&sharedTexDesc, NULL, &sharedTex11);       

        // Get the keyed mutex for the shared texture (for D3D11)///////////////////////////////////////////////////////////////
        hr = sharedTex11->QueryInterface(__uuidof(IDXGIKeyedMutex), (void**)&keyedMutex11);       

        // Get the shared handle needed to open the shared texture in D3D10.1///////////////////////////////////////////////////
        IDXGIResource *sharedResource10;
        HANDLE sharedHandle10;       

        hr = sharedTex11->QueryInterface(__uuidof(IDXGIResource), (void**)&sharedResource10);

        hr = sharedResource10->GetSharedHandle(&sharedHandle10);       

        sharedResource10->Release();

        // Open the surface for the shared texture in D3D10.1///////////////////////////////////////////////////////////////////
        IDXGISurface1 *sharedSurface10;       

        hr = d3d101Device->OpenSharedResource(sharedHandle10, __uuidof(IDXGISurface1), (void**)(&sharedSurface10));

        hr = sharedSurface10->QueryInterface(__uuidof(IDXGIKeyedMutex), (void**)&keyedMutex10);       

        // Create D2D factory///////////////////////////////////////////////////////////////////////////////////////////////////
        ID2D1Factory *D2DFactory;       
        hr = D2D1CreateFactory(D2D1_FACTORY_TYPE_SINGLE_THREADED, __uuidof(ID2D1Factory), (void**)&D2DFactory);       

        D2D1_RENDER_TARGET_PROPERTIES renderTargetProperties;

        ZeroMemory(&renderTargetProperties, sizeof(renderTargetProperties));

        renderTargetProperties.type = D2D1_RENDER_TARGET_TYPE_HARDWARE;
        renderTargetProperties.pixelFormat = D2D1::PixelFormat(DXGI_FORMAT_UNKNOWN, D2D1_ALPHA_MODE_PREMULTIPLIED);       

        hr = D2DFactory->CreateDxgiSurfaceRenderTarget(sharedSurface10, &renderTargetProperties, &D2DRenderTarget);

        sharedSurface10->Release();
        D2DFactory->Release();       

        // Create a solid color brush to draw something with               
        hr = D2DRenderTarget->CreateSolidColorBrush(D2D1::ColorF(1.0f, 1.0f, 1.0f, 1.0f), &Brush);

        //DirectWrite///////////////////////////////////////////////////////////////////////////////////////////////////////////
        hr = DWriteCreateFactory(DWRITE_FACTORY_TYPE_SHARED, __uuidof(IDWriteFactory),
                reinterpret_cast<IUnknown**>(&DWriteFactory));

hr = DWriteFactory->CreateTextFormat(L"Script",
NULL,DWRITE_FONT_WEIGHT_REGULAR,DWRITE_FONT_STYLE_NORMAL,DWRITE_FONT_STRETCH_NORMAL,50.0f,L"en-us",&TextFormat);

        hr = TextFormat->SetTextAlignment(DWRITE_TEXT_ALIGNMENT_LEADING);
        hr = TextFormat->SetParagraphAlignment(DWRITE_PARAGRAPH_ALIGNMENT_NEAR);

        d3d101Device->IASetPrimitiveTopology(D3D10_PRIMITIVE_TOPOLOGY_POINTLIST);       
        return true;
}

Need Suggestion to choose Visual Studio Version ...

$
0
0
Dear Sir ,

I am working on MFC App Wizard , Visual Studio 6 till now.

Now we need to go for Either Visual Studio 10 or Visual Studio 12.

Can you suggest which to choose ?

Can I migrate my code or Should I code everything new ?

Pl Suggest ..

New_2012
Viewing all 3017 articles
Browse latest View live