|
If you already know MFC's CString, then just use WTL which has its own CString.
--Mike--
Just released - RightClick-Encrypt - Adds fast & easy file encryption to Explorer
Like the Google toolbar? Then check out UltraBar, with more features & customizable search engines!
My really out-of-date homepage
Sonork-100.10414 AcidHelm
|
|
|
|
|
Hi,
I have a function that loads a file from harddisk. I'd like to add a second function that loads the file from the resource. How do I get a pointer to the data and the size of it?
<br />
BOOL LoadTGA(char* filename, char** ptr);<br />
BOOL LoadTGA(UINT nIDResource, char** ptr);
thx, Moak
|
|
|
|
|
HINSTANCE hInstance = LoadLibrary(pDLLPath);
HINSTANCE hInstance = AfxGetInstanceHandle();
HRSRC hRsrc;
if (hRsrc = FindResource(hInstance, pResourceName, pResourceType))
{
HGLOBAL hGlobal = LoadResource(hInstance, hRsrc);
if (hGlobal)
{
BYTE *pImage = (BYTE *)LockResource(hGlobal);
DWORD dwSize = SizeofResource(hInstance, hRsrc);
.... whatever
UnlockResource(hGlobal);
FreeResource(hGlobal);
}
}
(src)
-c
Cheap oil. It's worth it!
|
|
|
|
|
looks easy now
|
|
|
|
|
I always get an error when doing this procedure "The parameter is invalid.", here's how i call it. (pIdl is an ITEMIDLIST retrieved by calling SHBrowseForFolder, ghWnd is the handle to my window, and pNewId is modified by the EnumIDList->Next procedure)
IShellFolder *pBrowse = NULL;
IShellFolder *CurrentFolder = NULL;
ITEMIDLIST *pNewId;
char szFolderPath[MAX_PATH+1];
char szCompletePath[MAX_PATH+1];
WCHAR szTemp[MAX_PATH+1];
STRRET strDispName;
SHGetDesktopFolder (&CurrentFolder);
CurrentFolder->BindToObject(pIdl, NULL, IID_IShellFolder, (LPVOID*)&pBrowse);
SHGetPathFromIDList(pIdl, szFolderPath);
pBrowse->GetDisplayNameOf(pNewId, SHGDN_INFOLDER, &strDispName);
PathCombine(szCompletePath, szFolderPath, strDispName.cStr)
MultiByteToWideChar (CP_ACP, 0, szCompletePath, -1, szTemp, sizeof (szTemp) / sizeof (WCHAR));
pBrowse->ParseDisplayName(ghWnd, NULL, szTemp, NULL, &pNewId, NULL);
Thanks all!
|
|
|
|
|
I know many of you probably already have a function that does this, so I'll ask before I do a lot of searching.
I need a simple C function for generating the next prime number given an input number. The prototype for this would be something like:
int GetNextPrime(const int iAfter);
If iAfter is 90, then GetNextPrime would return 101.
I need this to optimize some code I am working on which must initialize the size of an MFC CMap hash table.
|
|
|
|
|
How is this different from lots of class assignment questions posted in the list?
|
|
|
|
|
Hello. I can see how this might be viewed as a class assignment since I know that this type of thing is found in CS courses.
Unfortunantely for me, I am not a student and have never taken any CS courses. I'm sure with some searching on google I can find this kind of thing, but since it is a low priority right now, I thought I would post on CP. It is something I need (eventually) to do with some of my code where I populate CMap objects with varying amounts of data.
Sorry for the confusion.
|
|
|
|
|
I was just kidding. Long time back GiLes posted some code in The Lounge that calculated prime numbers. You may look under his profile. Right now my Internet is running slow so I can't help you. CP Who's who search for Giles and look his messages you will be able to find.
|
|
|
|
|
Thanks for the info. I went ahead and searched google and found one just to avoid any confusion.
One question, though. I knew you could just run through all the numbers and try and divide it by every number less than it, but I was kinda hoping there was some kind of math trick to make it faster or something.
I guess my original question should have been: Is there a better way to calculate prime numbers than just checking each number by dividing it by every number less than it?
|
|
|
|
|
Matt Gullett wrote:
knew you could just run through all the numbers and try and divide it by every number less than it, but I was kinda hoping there was some kind of math trick to make it faster or something
Of course there is. You need to check numbers up to square root of tested one.
Tomasz Sowinski -- http://www.shooltz.com
- It's for protection - Protection from what? Zee Germans?
|
|
|
|
|
Thanks, that's exactly what I was looking for.
I probably should have known that, but it never crossed my mind.
|
|
|
|
|
Matt Gullett wrote:
I probably should have known that, but it never crossed my mind.
But you know that you can ignore even numbers?
Tomasz Sowinski -- http://www.shooltz.com
- It's for protection - Protection from what? Zee Germans?
|
|
|
|
|
And numbers where n%6 is neither 1 nor 5.
|
|
|
|
|
Matt, here is a Java implementation that you could port to C/C++.
/ravi
"There is always one more bug..."
http://www.ravib.com
ravib@ravib.com
|
|
|
|
|
Matt Gullett wrote:
If iAfter is 90, then GetNextPrime would return 101.
Why don't you want 97?
If you're willing to pay a speed penalty (but for such small primes I don't think you'll notice) you could implement it as:
unsigned int GetNextPrime(unsigned int val)<br />
{<br />
val |= 1;<br />
while (!IsPrime(prev)) val += 2;<br />
return val;<br />
}<br />
The excercise for you would be the IsPrime function.
If you want a more generic solution for larger numbers (still < 31 bits), may I suggest you have a look at the NTL Number Theory Library and its PrimeSeq class.
|
|
|
|
|
Thanks.
Mike Nordell wrote:
Why don't you want 97?
Oh yea. 97 is a prime.;)
Thanks for the idea. I went ahead and implemented my code yesterday. I did something very similar to what you suggested. Very simple.
Amazingly, simply increasing my hash table size by 20% + using a prime number made a 11% improvement in performance for those operations.
|
|
|
|
|
The following chunk of code is supposed to loop through my CRichEdit control and get each line and show it in a messagebox.. eventually instead this will use a line printing function to print what is in the rich edit control.. heres the code:
void CTextViewer::OnBnClickedPrintbutton()
{
int i, nLineLength, nLineCount = m_edtRichEdit.GetLineCount();
CString strText, strLine;
for (i = 0; i < nLineCount; i++)
{
nLineLength = m_edtRichEdit.LineLength(i);
m_edtRichEdit.GetLine(i, strText.GetBuffer(nLineLength));
AfxMessageBox(strText.GetBuffer(0));
strText.ReleaseBuffer(nLineLength);
}
} heres the error:
Debug Error!
Program : ... blah.exe
DAMAGE: after Normal block (#3741) at 0x002F6B48. debugging throws me into dbgheap.c at _CRTIMP int __cdecl _CrtIsValidHeapPointer(
if i trace through it actually goes through all of the lines, and shows em all on the screen, but as it exits the function it gets this heap error.. any ideas? i copied the richedit example exactly and then modified it, but even unmodified i get the same error.. i thought maybe it was the \n's in my text, but i got rid of all those and have the same prob..
-dz
|
|
|
|
|
Remove GetBuffer(0) from AfxMessageBox call. CString has a LPCTSTR conversion operator.
Tomasz Sowinski -- http://www.shooltz.com
- It's for protection - Protection from what? Zee Germans?
|
|
|
|
|
still get same series of errors.. i don't really understand this buffer stuff.. i am only familiar with strings.. here is the current look of it:
void CTextViewer::OnBnClickedPrintbutton()
{
int i, nLineLength, nLineCount = m_edtRichEdit.GetLineCount();
CString strText, strLine;
for (i = 0; i < nLineCount-1; i++)
{
nLineLength = m_edtRichEdit.LineLength(i);
m_edtRichEdit.GetLine(i, strText.GetBuffer(nLineLength));
AfxMessageBox(strText);
strText.ReleaseBuffer(nLineLength);
}
}
it is crashing as it exits the function, so im assuming the buffers are somehow messing up the deconstructors?
-dz
|
|
|
|
|
Probably the problem is related to the fact that your buffer should be big enough to hold number of characters in line in first 4 bytes. So you should change two things:
1) increase value passed to GetBuffer by 4
2) use 3-argument version of CRichEditCtrl::GetLine
See EM_GETLINE docs for more information.
Tomasz Sowinski -- http://www.shooltz.com
- It's for protection - Protection from what? Zee Germans?
|
|
|
|
|
Hi
I want to find the default dns server address / default gateway programatically.
Here is a sample output while running ipconfig.exe /all
___________________________________________________________
D:\>ipconfig /all
Windows IP Configuration
Host Name . . . . . . . . . . . . : s
Primary Dns Suffix . . . . . . . :
Node Type . . . . . . . . . . . . : Unknown
IP Routing Enabled. . . . . . . . : Yes
WINS Proxy Enabled. . . . . . . . : Yes
PPP adapter Dishnet:
Connection-specific DNS Suffix . :
Description . . . . . . . . . . . : WAN (PPP/SLIP) Interface
Physical Address. . . . . . . . . : 00-53-45-00-00-00
Dhcp Enabled. . . . . . . . . . . : No
IP Address. . . . . . . . . . . . : 202.9.156.173
Subnet Mask . . . . . . . . . . . : 255.255.255.255
Default Gateway . . . . . . . . . : 0.0.0.0
DNS Servers . . . . . . . . . . . : 202.9.152.11
202.9.145.6
NetBIOS over Tcpip. . . . . . . . : Disabled
___________________________________________________________
Now there it is written DNS servers. How can I find dns servers through code.
Shrishail Rana
|
|
|
|
|
#include <iads.h>
#include <windows.h>
#include <windns.h>
#include <winsock.h>
#include <winerror.h>
#include "stdafx.h"
#include <activeds.h>
#include <stdio.h>
int main(void)
{
PDNS_RECORD pDnsRecord;
DNS_STATUS status;
char szNameBuf[64];
struct hostent *hostinfo;
WORD wVersionRequested = MAKEWORD(1,1);
WSADATA wsaData;
in_addr address;
printf("DNS Server lookup ...!\n");
// Get host by name
if ( WSAStartup(wVersionRequested, &wsaData) )
return 0;
if ( gethostname(szNameBuf,64) )
return 0;
if ( (hostinfo = gethostbyname(szNameBuf)) == NULL )
return 0;
// End Get host by name
// Reverse order
// reverse the byte-order
address.S_un.S_addr = ntohl(*((DWORD*) hostinfo->h_addr_list[0]));
// use "dotted" string format
sprintf(szNameBuf, "%s.in-addr.arpa", inet_ntoa(address));
status =
DnsQuery_A( szNameBuf,
DNS_TYPE_PTR,
DNS_QUERY_BYPASS_CACHE,
NULL,
&pDnsRecord,
NULL );
|
|
|
|
|
Hi,
Is it possible to download ATL 7.0 to use it under VC++ 6.0?
WTL 7.0 is available but not ATL 7.0.
Thanks,
Francisco
|
|
|
|
|
Sadly not.
Michael
Errata 1: p. 154, section 'Defusing'. For 'red wire' read 'blue wire'.
|
|
|
|