|
Thanks for the help Leon!!
I did manage to get the bmp code working good, however, I noticed as I compressed the bmp further and further with StretchBlt() it got ugly...
When I tried using your JPG/GIF loading code, was it supposed to proc a Dlgbox? or no? I had some trouble with the LPOLESTR converting from my program... but I think I got that fixed... here's the code:
HDC MemDCFromJPG_GIF_File(CString filename, int iWidth, int iHeight)
{
const int HIMETRIC_PER_INCH = 2540;
SIZE sizeInHiMetric;
IPicture* Ipic = NULL;
HDC MemDC = 0; // Preset return value to fail
BSTR b = filename.AllocSysString();
LPOLESTR pOLE_stringpath = b;
HRESULT hr = OleLoadPicturePath(pOLE_stringpath, NULL, 0, 0,
IID_IPicture, (LPVOID*)&Ipic); // Load the picture
if ((hr == S_OK) & (Ipic != 0)) // Picture loaded okay
{
...
However, the Ipic pointer is returning NULL every time? I don't know how to fix that??
Thanks again for your help!
Ryan.
|
|
|
|
|
Did you take note of the comment
Due to the way OLE works filename must be fully qualified (ie c:\folder\a.jpg)
That is usually the first port of call to why OleLoadPicturePath fails.
In vino veritas
|
|
|
|
|
Maybe it's so close to me I just can't see it. I have an application of a little north of 100K of source. I need to determine how much static allocation is going on and from where. Traditionally, I would just ask for a map file where it would list all of this out. But the VS2008 map file is useless. Lots of data, no real information. Am I missing something? I need the section that shows me where static variables are being allocated.
cg
Charlie Gilley
<italic>Stuck in a dysfunctional matrix from which I must escape...
"Where liberty dwells, there is my country." B. Franklin, 1783
“They who can give up essential liberty to obtain a little temporary safety deserve neither liberty nor safety.” BF, 1759
|
|
|
|
|
Hi Charlie,
It's been a while since I've worked with the Debug Interface Access SDK[^] but I believe the Dia2dump Sample[^] will dump all of your allocated variables along with with size and location.
Best Wishes,
-David Delaune
|
|
|
|
|
Oh if this works, Christmas has come early! I'll check it out.
Thanks
Charlie Gilley
<italic>Stuck in a dysfunctional matrix from which I must escape...
"Where liberty dwells, there is my country." B. Franklin, 1783
“They who can give up essential liberty to obtain a little temporary safety deserve neither liberty nor safety.” BF, 1759
|
|
|
|
|
charlieg wrote: Oh if this works, Christmas has come early! I'll check it out. You make it sound as if you are the only developer that has ever had this requirement. There are dozens of commercial and open source products that have the capability.
List of performance analysis tools[^]
Intel VTune is probably the easiest to use and has a lower learning curve. There is also a free trial version.
Best Wishes,
-David Delaune
|
|
|
|
|
I am new to C++17, and am trying to figure out how to use string_view. I have three functions that parse a string of comma separated values:
beforecomma reports the string before the first comma,
aftercomma reports the string after the first comma,
and
slicecomma returns the string before the first comma and updates the original string to that part after the first comma.
These functions all work properly in their current forms using just string. Now, I am trying to update them as beforecomma2, aftercomma2, and slicecomma2, to take advantage of string_view. However, I am getting some unexpected results. I am hoping someone out there can tell me why this is happening and what I am doing wrong.
First, the functions:
std::string_view beforecomma2 (std::string_view line)
{
auto found = line.find(',');
if (found!=std::string::npos)
{return line.substr(0,found);}
else return line;
}
string_view aftercomma2 (string_view line)
{
auto found = line.find(',');
if ((found==std::string::npos) || (found==line.size()-1)) return "";
else
{
std::string_view out=line.substr(found+1,line.size());
while ((out[0]==' ') && (out.size()>0)) out=out.substr(1,out.size());
return out;
}
}
string_view slicecomma2 (string& line)
{
auto found=line.find(',');
if (found==std::string::npos)
{
return line;
}
else
{
string_view out=beforecomma2(line);
line=aftercomma2(line);
return out;
}
}
I run these functions with the following main, that just calls the functions beforecomma2 and aftercomma2.
int main (int argc, char* argv[])
{
string test="01234, 5678, 90, 78902, 999999, 333333";
cout << test << endl;
cout << beforecomma2(test) << endl; test=aftercomma2(test);
cout << beforecomma2(test) << endl; test=aftercomma2(test);
cout << beforecomma2(test) << endl; test=aftercomma2(test);
cout << beforecomma2(test) << endl; test=aftercomma2(test);
cout << beforecomma2(test) << endl; test=aftercomma2(test);
cout << beforecomma2(test) << endl; test=aftercomma2(test);
return 1;
}
I get the expected output of:
01234, 5678, 90, 78902, 999999, 333333
01234
5678
90
78902
999999
333333
So far, so good. Now I try to combine these two functions into a single function, slicecomma2, implemented as:
int main (int argc, char* argv[])
{
string test="01234, 5678, 90, 78902, 999999, 333333";
PrintString(test);
cout << slicecomma2(test) << endl;
cout << slicecomma2(test) << endl;
cout << slicecomma2(test) << endl;
cout << slicecomma2(test) << endl;
cout << slicecomma2(test) << endl;
cout << slicecomma2(test) << endl;
return 1;
}
Now I get the output of:
01234, 5678, 90, 78902, 999999, 333333
5678,
90,
78
99999
333333
33333
A few things wrong here.
First, the first item 01234 is skipped.
Second, a comma appears with the second and third printed items, when it should not.
Third, the fourth and fifth items are truncated to 78 when it should be 78902 and 99999 when it should be 999999
Fourth the last item, 333333, should not be repeated and should not appear truncated with a leading space.
So, it is not working as I expected it to work.
I would say that there is something here that I do not understand about string_view, but since I do not understand it I do not know what that is. Can anyone enlighten me?
Thank you.
|
|
|
|
|
The string_view is a view into an existing string. The string it is looking at must still be available as long as you want to use the string_view.
Your slicecomma2 function is creating a string_view from the line string but then it is changing the line string, making the contents of the string_view invalid.
|
|
|
|
|
Of course, I see that now.
I knew I was making some type of stupid mistake, but those are always the hardest for me to catch and correct.
Thank you for your response.
|
|
|
|
|
Hello recreational and professional programmers.
I need you to tell me everything you wish you had access to/known/ been encouraged to explore with programming at a young age.
My son has been interested in coding since he was 4. My dad and him began to learn it together for fun, but he has long passed my dad's abilities at age 10. He can write many languages from memory and often hand-writes pages of coding in his notebooks while at school. Sometimes I think he dreams in code. He also really loves math and chemistry.
I do not know how to help him. There are no resources available for his age group in our area- it is all geared towards high school students, with a high focus on cyber security (which is awesome, just not alot of choices). He is bored with CodeAcademy. I don't really even understand a lot of what he is saying...
Is there an online program for kids, or a well-monitored program with all ages, that he can share his ideas, learn from others, be helped towards the direction he is interested in going? Like, an extracurricular of sorts, but for programmer kids!?
Sorry for the long post... any and all advice is welcomed.
|
|
|
|
|
Please don't post the same thing in multiple places - you have it in QA as well, and duplicating work doesn't help anyone...
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
i want to make password in star form with this code anyone can do this?
// password
LOGINP:
clrscr();
printf("\n\n\n\n\nUsername: its_vishuuuu");
gotoxy(x,y);
printf("Login\n\n\t\t\tPassword: ");
fflush(stdin);//covert char to int screen
gets(pass1);//enter string
check=strcmp(pass1,password1);//check password
if(check!=0)
{
clrscr();
goto LOGINP;
}
|
|
|
|
|
Getting an input string without echoing it on the screen it is not a standard ANSI C feature. You should check if your system provide some non-standard way to do it, like Linux 's getpass[^].
|
|
|
|
|
You could try putting _getch() in a loop, printing a '*' for each character typed.
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles
|
|
|
|
|
Unfortunately there is no way in standard C/C++ to do that, but I see you're already using non-standard functions anyway. As David pointed out, _getch() should do the trick:
#include "stdio.h"
#include "conio.h"
int main()
{
char c;
c = _getch();
putchar('*');
printf("\nYou entered %c\n", c);
_getch(); return 0;
}
If this doesn't work, refer to this thread for more advice: c++ - Capture characters from standard input without waiting for enter to be pressed - Stack Overflow[^]
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)
|
|
|
|
|
char* str = new char[128];
At first run, the address of str is 0x12345678,
and second run, the address of str is 0x00123456,
I want the address of str constant, not change every time run.
I wish:
At first run, the address of str is 0x12345678,
and second run, the address of str is 0x12345678,
every time run, the address of str is 0x12345678.
|
|
|
|
|
There's no mechanism within C++ to do that. In fact, modern run time systems are designed so that program data spaces are different for each program invocation. For example:
$ cat example.c
#include <stdio.h>
int main()
{
int n;
printf("&n = %p\n" , &n);
}
$ for ((i=0;i<4;++i)); do ./example; done
&n = 0x7fff2ddda67c
&n = 0x7ffdece1243c
&n = 0x7ffe42e7d2bc
&n = 0x7fffd2e78b2c
$
Note that even this simple program gives different addresses for the address of int n on successive runs. This is to make it difficult for any malicious program to interfere with and modify a running program, or to predict where a program will place data.
Also note that in any modern OS (outside of some embeded applications), you are dealing with virtual addresses anyway, so where your process thinks an object is and where the object actually is in physical memory are completely different, so you need to know things like the value page frames and things to work out a physical address of an object in memory.
Outside of some sort of educational value, I can't see any up side to always getting the same address when calling new , so maybe you might want to think about why you want this behavior and come up with a new plan.
|
|
|
|
|
|
You could mimic that implementing you own memory manager and then globally replacing the default new operator.
|
|
|
|
|
|
Are you referring to either the /base or /fixed linker option?
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles
|
|
|
|
|
First, I use Visual Studio.
Invalid after adding add "/fixed" linker option.
and
error LNK1146: no argument specified with option '/base'
|
|
|
|
|
The question is stupid, there is no way a dynamic heap manager can guarantee it wont give the memory space away to some other call for memory allocation. To do what you asked it would have to keep the memory "available" anyhow, so for the love of all things coding just declare the thing static in that case (unless you actually want a global).
My C++ is rusty with string objects but it should be something like
static char* str = char[128];
In C it is simpler
static char str[128];
Problem solved it now has the same address everytime locally, and effectively does the same thing that any crazy heap manager doing what you asked would have to do.
I am assuming you are going to change the string at times, so you want a variable not a constant.
In vino veritas
modified 13-Nov-19 8:47am.
|
|
|
|
|
The first form is not valid C++. And the second form still does not work since the compiler and the linker can allocate that array in different places.
As you so rightly say, the question is stupid.
|
|
|
|
|
Main Question: Is it possible to set a tree item image (CTreeCtrl::SetItemImage) without having to build a CImageList ?
I have to build different images corresponding to the items state and I would like to be able to create the image dynamically (lot of TransparentBlt) instead of having to list and build all the images and add them statically to the image list.
i have a default item image and I TransparentBlt state images on it
for example, an item can have the state1 enabled, and will display the appropriate image representing state1.
an another item can have state1 and state4 and will display an image with the state1 and state4
Now, I have to create the imagelist for all combinations of states at compile time and call the SetItemImage with the image list index.
I'd like to be able to simply call something like:
myTree.SetItemImage( hItem, BuildMyItemImage(hItem ) );
I'd rather be phishing!
|
|
|
|
|