|
I am posting compiled code. As stated above Freelist[i] fails. Highlighted the statement causing error.
#include <<windows.h>> // remove extra angle bracket for compilation
#include <<tchar.h>>
#include <<stdio.h>>
#include <<strsafe.h>>
void FreeMemory(char** myArray, int row);
void FileCountInDir(const TCHAR* dirpath, int * filescount, int* filesize);
void FindFilesInDirectory(const TCHAR* dirpath, char** filelist);
int _tmain(int argc, TCHAR *argv[])
{
int i =0;
TCHAR szDirpath[MAX_PATH];
//TCHAR Filelist[100][MAX_PATH];
char ** Filelist;
int iFileCountInFolder=0;
int iFileSize = 0;
_tcscpy(szDirpath,_T("C:\\BMPread_W\\TransitionEffects\\Images"));
FileCountInDir(szDirpath,&iFileCountInFolder,&iFileSize);
Filelist = (char**)malloc(iFileCountInFolder * sizeof(char *));
if(Filelist == NULL)
{
fprintf(stderr, "out of memory\n");
return 0;
}
for(i = 0; i < iFileCountInFolder; i++)
{
Filelist[i] = (char*)malloc((iFileSize * sizeof(char))+1);
if(Filelist[i] == NULL)
{
fprintf(stderr, "out of memory\n");
return 0;
}
}
FindFilesInDirectory(szDirpath, Filelist);
for(i =0;i<ifilecountinfolder;i++)
{
="" _tprintf(text("%s\n"),filelist[i]);
="" }
="" freememory(filelist,ifilecountinfolder);
="" return="" 0;
}
void="" findfilesindirectory(const="" tchar*="" dirpath,="" char**="" filelist)
{
="" list="" all="" the="" files="" in="" directory="" with="" some="" info="" about="" them.
="" win32_find_data="" ffd;
="" tchar="" szdir[max_path];
="" szfilefullpath[max_path]="{0};
" int="" filenumber="0;
" handle="" hfind="INVALID_HANDLE_VALUE;
" dword="" dwerror="0;
" _tcscpy(szdir,="" dirpath);
="" _tcscat(szdir,_t("\\*"));
="" &ffd);
="" if="" (invalid_handle_value="=" hfind)=""
="" ;
="" }="" do
="" (ffd.dwfileattributes="" &="" file_attribute_directory)
="" do="" nothing
="" else
="" _tcscpy(szfilefullpath,dirpath);
="" _tcscat(szfilefullpath,_t("\\"));
="" _tcscat(szfilefullpath,ffd.cfilename);
="" memcpy(filelist[filenumber],="" ffd.cfilename,="" sizeof(ffd.cfilename));
="" filenumber++;
="" while="" (findnextfile(hfind,="" &ffd)="" !="0);
" findclose(hfind);
}
void="" filecountindir(const="" *="" filescount,="" int*="" filesize)
{
="" szfilefullpath="{0};
" &ffd);
="" (*filescount)++;
="" if(="" ((*filesize)="=" 0)="" &&="" (_tcslen(ffd.cfilename)=""> 0)|| ((*filesize) < _tcslen(ffd.cFileName)))
{
(*filesize) = _tcslen(ffd.cFileName);
}
}
}
while (FindNextFile(hFind, &ffd) != 0);
FindClose(hFind);
}
void FreeMemory(char** myArray, int row)
{
int i;
if(myArray != NULL)
{
for (i = 0; i < row; i++){
free (myArray[i]);
}
}
|
|
|
|
|
Firstly you should employ assert() to help you. This is a classic situation where many asserts can assist.
By the look of your code iFileCountInFolder can change during execution. If it does get bigger on the free than on the malloc then "poof".
Peter Wasser
"The whole problem with the world is that fools and fanatics are always so certain of themselves, and wiser people so full of doubts." - Bertrand Russell
|
|
|
|
|
iFileCountInFolder is always fixed, since the files in a folder are fixed , means no files are added at run time.
I did not understand why the Free statement is failing.
|
|
|
|
|
There are many options to define values for flags, here is a list of known by me:
- Hexadecimal: 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, ...
- Decimal: 1, 2, 4, 8, 16, 32, 64, 128, ...
- Bit Shifting of 1: 1<<0, 1<<1, 1<<2, 1<<3, 1<<4, ...
- 2 * previous a=1, b=a*2, c=b*2, d=c*2, e=d*2, ...
Do you know any other?
Which do you consider as the best, and why?
Do you define (give it a name) an empty member (0) in flags?
|
|
|
|
|
- Any other is just a variation of the above, which are all basically the same. The only 'difference' is the visual representation.
- Hexadecimal is best as it makes it obvious what each bit represents, and is easy to visualise when flags are used in combination.
- Only define a zero value if it has any specific meaning.
|
|
|
|
|
I mostly use hex flags, I think that's the most common method. It's probably because it's a lot clearer which bits are actually set (for that same reason, I don't think I've ever seen decimal used for flags since the conversion isn't as neat).
Empty flags have a definition if they have a meaning (i.e. not necessary but could be labeled for clarity).
|
|
|
|
|
Dear all:
I try to use WH_CALLWNDPROC and PT_TOUCH in dll to get the global touch event. But I get some problems. My code lists as below:
#pragma data_seg (".SHARED")
HHOOK g_hPreviousMouseHook = 0;
HINSTANCE g_hInstance = 0;
#pragma data_seg()
#pragma comment(linker, "/SECTION:.SHARED,RWS")
BOOL CSoundDllApp::InitInstance()
{
CWinApp::InitInstance();
g_hInstance = AfxGetInstanceHandle();
return TRUE;
}
BOOL InstallWinHook()
{
BOOL bReturn = TRUE;
g_hPreviousMouseHook = SetWindowsHookEx(WH_CALLWNDPROC,
&WinHookProcedure, g_hInstance, 0);
if(NULL == g_hPreviousMouseHook)
{
bReturn = FALSE;
}
return bReturn;
}
BOOL UnInstallWinHook()
{
BOOL bReturn = TRUE;
if(UnhookWindowsHookEx(g_hPreviousMouseHook) == FALSE)
{
bReturn = FALSE;
}
return bReturn;
}
LRESULT CALLBACK WinHookProcedure(int nCode, WPARAM wParam, LPARAM lParam)
{
if(0 > nCode)
return CallNextHookEx(g_hPreviousMouseHook, nCode,
wParam, lParam);
UINT32 pointerId = GET_POINTERID_WPARAM(wParam);
POINTER_INPUT_TYPE pointerType;
if(GetPointerType(pointerId, &pointerType))
{
}
return CallNextHookEx(g_hPreviousMouseHook, nCode, wParam,
lParam);
}
When I disable the GetPointerType(pointerId, &pointerType) in
WinHookProcedure, it will load the dll success. When I enable the
GetPointerType(pointerId, &pointerType) in WinHookProcedure, it
will load the dll failed. what happened? Could someone tell me
please?
Thanks for your help, Victor
|
|
|
|
|
Hi All,
Kindly provide these below details.
Where i can get the license and setup for visual studio 6.0 enterprise edition for visual c++ 6.0 And
Plz let me know, any service pack required for Visual studio 6.0 to install on windows 7 Operating system.
Thanks & Regards,
TV Krishna Rayalu
|
|
|
|
|
You can try to buy it somewhere (e.g. from Ebay or Amazon).
I don't think that it can be used without problems with Windows 7. It may even fail to install. You should install it using the XP mode of Windows 7.
The VS 6 service packs are no longer present on the Microsoft web sites. When buying a used version you may ask the seller if he still has the service packs. The service packs are not related to the OS version where VS 6 is installed but contain fixes for VS 6 itself.
|
|
|
|
|
I successfully installed VS6 on a Windows 7 SP1 machine a few years back. The only trouble I ran into was with MDAC, since Windows 7 had a newer version. Make sure to install it as Administrator.
"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
|
|
|
|
|
Building / compiling DirectShow DLL
I am still not sure how this “empty DLL” is being compiled.
Here is an example of DirctShow sample (Synth ) direct from SDK 8.1.
I am using #pragma message to see the flow of compilation.
I compiles / links just fine , but the commonly used $ifndef / #define preprocessed flag does not stop multiple passes thru the source files.
Here is the build output.
<pre lang="c++">Compiling resources...
Compiling...
dynsrc.cpp
synth.cpp
Compiling D:\00\0 SDK\DirectShow SDK 8.1 new\DXF\DXSDK\samples\Multimedia\DirectShow\Filters\Filter_Base\dynsrc.cpp
Last modified on Sun Mar 23 10:23:52 2014
File: DynSrc.cpp
implements CDynamicSource, which is a Quartz source filter
#include <streams.h>
#include <streams.h>
#include DynSrc.h
File: DynSrc.h
DirectShow sample code - defines classes to simplify creation of
ActiveX source filters that support continuous generation of data
Compiling D:\00\0 SDK\DirectShow SDK 8.1 new\DXF\DXSDK\samples\Multimedia\DirectShow\Filters\Filter_Base\DynSrc.h
Last modified on Sun Mar 23 09:52:24 2014
#define __CDYNAMICSOURCE__ START
define CDynamicSource class
define CDynamicSourceStream class
#define __CDYNAMICSOURCE__ END
#include DynSrc.h
synthprp.cpp
Compiling ***MODIFIED***C:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\initguid.h
Last modified on Sun Mar 2 13:48:42 2014
Definitions for controlling GUID initialization
File: DynSrc.h
DirectShow sample code - defines classes to simplify creation of
ActiveX source filters that support continuous generation of data
Compiling D:\00\0 SDK\DirectShow SDK 8.1 new\DXF\DXSDK\samples\Multimedia\DirectShow\Filters\Filter_Base\DynSrc.h
Last modified on Sun Mar 23 09:52:24 2014
#define __CDYNAMICSOURCE__ START
define CDynamicSource class
define CDynamicSourceStream class
#define __CDYNAMICSOURCE__ END
A_Test.cpp
Generating Code...
Compiling D:\00\0 SDK\DirectShow SDK 8.1 new\DXF\DXSDK\samples\Multimedia\DirectShow\Filters\Filter_Base\A_Test.cpp
Last modified on Sun Mar 23 09:40:08 2014
Linking...
Creating library Debug/synth.lib and object Debug/synth.exp
synth.ax - 0 error(s), 0 warning(s)
<pre>
Here is a sceond issue, probably related to first one.
So I tried to stop the compilation using #error. It gives expected output , but does not stop the compilation. Here is the output.
<pre lang="c++">Compiling resources...
Compiling...
dynsrc.cpp
Compiling D:\00\0 SDK\DirectShow SDK 8.1 new\DXF\DXSDK\samples\Multimedia\DirectShow\Filters\Filter_Base\dynsrc.cpp
Last modified on Sun Mar 23 10:37:23 2014
File: DynSrc.cpp
implements CDynamicSource, which is a Quartz source filter
D:\00\0 SDK\DirectShow SDK 8.1 new\DXF\DXSDK\samples\Multimedia\DirectShow\Filters\Filter_Base\dynsrc.cpp(19) : fatal error C1189: #error : STOP
synth.cpp
synthprp.cpp
Compiling ***MODIFIED***C:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\initguid.h
Last modified on Sun Mar 2 13:48:42 2014
Definitions for controlling GUID initialization
File: DynSrc.h
DirectShow sample code - defines classes to simplify creation of
ActiveX source filters that support continuous generation of data
Compiling D:\00\0 SDK\DirectShow SDK 8.1 new\DXF\DXSDK\samples\Multimedia\DirectShow\Filters\Filter_Base\DynSrc.h
Last modified on Sun Mar 23 09:52:24 2014
#define __CDYNAMICSOURCE__ START
define CDynamicSource class
define CDynamicSourceStream class
#define __CDYNAMICSOURCE__ END
A_Test.cpp
Generating Code...
Compiling D:\00\0 SDK\DirectShow SDK 8.1 new\DXF\DXSDK\samples\Multimedia\DirectShow\Filters\Filter_Base\A_Test.cpp
Last modified on Sun Mar 23 09:40:08 2014
Error executing cl.exe.
synth.ax - 1 error(s), 0 warning(s)
<pre>
So I did #define DEBUG, and got this build output. It complained about DEBUG redefinition. It still did not stopped the compilation, but used the #idndef / #define flags correctly.
<pre lang="c++">Compiling resources...
Compiling...
dynsrc.cpp
Compiling D:\00\0 SDK\DirectShow SDK 8.1 new\DXF\DXSDK\samples\Multimedia\DirectShow\Filters\Filter_Base\dynsrc.cpp
Last modified on Sun Mar 23 10:40:57 2014
D:\00\0 SDK\DirectShow SDK 8.1 new\DXF\DXSDK\samples\Multimedia\DirectShow\Filters\Filter_Base\dynsrc.cpp(13) : warning C4005: 'DEBUG' : macro redefinition
unknown(0) : see previous definition of 'DEBUG'
File: DynSrc.cpp
implements CDynamicSource, which is a Quartz source filter
D:\00\0 SDK\DirectShow SDK 8.1 new\DXF\DXSDK\samples\Multimedia\DirectShow\Filters\Filter_Base\dynsrc.cpp(19) : fatal error C1189: #error : STOP
synth.cpp
synthprp.cpp
Compiling ***MODIFIED***C:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\initguid.h
Last modified on Sun Mar 2 13:48:42 2014
Definitions for controlling GUID initialization
File: DynSrc.h
DirectShow sample code - defines classes to simplify creation of
ActiveX source filters that support continuous generation of data
Compiling D:\00\0 SDK\DirectShow SDK 8.1 new\DXF\DXSDK\samples\Multimedia\DirectShow\Filters\Filter_Base\DynSrc.h
Last modified on Sun Mar 23 09:52:24 2014
#define __CDYNAMICSOURCE__ START
define CDynamicSource class
define CDynamicSourceStream class
#define __CDYNAMICSOURCE__ END
A_Test.cpp
Generating Code...
Compiling D:\00\0 SDK\DirectShow SDK 8.1 new\DXF\DXSDK\samples\Multimedia\DirectShow\Filters\Filter_Base\A_Test.cpp
Last modified on Sun Mar 23 09:40:08 2014
Error executing cl.exe.
synth.ax - 1 error(s), 1 warning(s)
</pre>
I would like to hear from somebody familiar with building DirectShow filters from scratch.
I really do not need another lecture on how preprocessor works.
I did read the samples posted here, but they really do not explain the build process, especially the compilation.
Thanks in advance.
Cheers
Vaclav
PS If this post looks goofy as far as text and code goes, sorry I could not get preview to work.
|
|
|
|
|
Vaclav_Sal wrote: If this post looks goofy as far as text and code goes, sorry I could not get preview to work. You need to clear the checkbox below the edit window titled "Treat my content as plain text, not as HTML".
|
|
|
|
|
In a WinCE MFC program, OnInitDialog(), I changed font of a Static text, but, it shows messy characters. same logic in my PC, I wrote a test MFC program. it works well.
Please help me to analyze the reason.
BOOL CTestDlg::OnInitDialog()
{
CDashApp *pApp ;
CDialog::OnInitDialog();
pApp = (CDashApp *) AfxGetApp();
ShowCursor( FALSE ) ;
InitConfigurationFile();
LoadDtcFile( pApp->g_PanelSettings.language );
if ( NULL != AddFontResource(TEXT("\\FlashDisk\\Startup\\FZYTK.TTF")) ) {
::SendMessage(HWND_BROADCAST,WM_FONTCHANGE,0,0);
}
DrawDash( BKG_DRAW ) ;
RefreshMainScreen( );
pApp->m_ActiveDlg = ACTIVE_DLG_TEST ;
LOGFONT lf;
CStatic *pEdit2 = new CStatic;
memset(&lf, 0, sizeof(LOGFONT));
lf.lfQuality = CLEARTYPE_QUALITY;
lf.lfWidth = 0;
WCHAR lffn[] = TEXT("FZYaoTi(OpenType)");
wcscpy(lf.lfFaceName,lffn);
lf.lfCharSet = GB2312_CHARSET;
if (m_Font1.m_hObject) {
m_Font1.DeleteObject();
}
m_Font1.CreateFontIndirect(&lf);
pEdit2 = (CStatic*)GetDlgItem( IDC_INFO_TOP);
GetDlgItem( IDC_INFO_TOP)->SetFont(&m_Font1,1);
pEdit2->SetWindowTextW(_T("??"));
return TRUE; }
|
|
|
|
|
Is the font installed on the target machine ?
~RaGE();
I think words like 'destiny' are a way of trying to find order where none exists. - Christian Graus
Entropy isn't what it used to.
|
|
|
|
|
... and MSDN says CreateFontIndirect would work for desktop apps only, so ...
~RaGE();
I think words like 'destiny' are a way of trying to find order where none exists. - Christian Graus
Entropy isn't what it used to.
|
|
|
|
|
Thanks, CreateFontIndrect work for WinCE also.
Now it solved. seems when the IDE pop up a message window, ask me if I hope to change the character set, I clicked no.
|
|
|
|
|
Hi everyone,
here is an old and for me, still, an unanswered question:
How can I programmatically set width of an drop-down auto-complete list drawn implementing IAutoComplete2 interface, without re-sizing
of corresponding edit control, for example overriding edit controls WndProc? Is it possible at all on XP and up?
Thank You.
|
|
|
|
|
A dialog based program, I put a function to draw a string on the screen. the function is member function of TestDlg.h;
But if I put the function in TestDlg.cpp, the screen show some weird messy characters.
Then I put the same function in another cpp file, most of this file are global functions. JTest.cpp, with Jtest.h.
Weird thing is it works, screen can show correct characters.
Situation like:
TestDlg.cpp
IMPLEMENT_DYNAMIC (CTestDlg,CDialog)
...
void TestDlg::DrawInfoLabel(void)
{
CDC* pDC;
CRect rect(562,448,688,467);
CString lebelStr;
HDC hDC;
LOGFONT lf;
HFONT FontNew, FontOld;
pDC = GetDC();
hDC = pDC->GetSafeHdc();
memset(&lf, 0, sizeof(LOGFONT));
lf.lfHeight = -14 * GetDeviceCaps(hDC,LOGPIXELSY)/72;
lf.lfWeight = 0;
WCHAR lffn[] = TEXT("FZYaoTi(OpenType)");
wcscpy(lf.lfFaceName,lffn);
lf.lfCharSet = GB2312_CHARSET;
FontNew = CreateFontIndirect(&lf);
FontOld = (HFONT)SelectObject(hDC,FontNew);
pDC->SetTextColor(RGB(0xFF,0x00,0x00));
SetBkMode(hDC,TRANSPARENT);
DrawText(hDC,_T("??"),-1,rect,DT_CENTER|DT_VCENTER|DT_SINGLELINE);
SelectObject(hDC,FontOld);
DeleteObject(FontNew);
ReleaseDC(pDC);
}
In JTest.cpp
void TestDlg::DrawInfoLabel(void)
{
....
}
Every line is same, only difference is file name. I feel it is the following statement affect the screen output.
IMPLEMENT_DYNAMIC (CTestDlg,CDialog)
#include "resource.h"
#define APSTUDIO_READONLY_SYMBOLS
#include "afxres.h"
#include "newres.h"
#undef APSTUDIO_READONLY_SYMBOLS
#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU)
#ifdef _WIN32
LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US
#endif //_WIN32
#ifdef APSTUDIO_INVOKED
1 TEXTINCLUDE
BEGIN
"resource.h\0"
END
2 TEXTINCLUDE
BEGIN
"#include ""afxres.h""\r\n"
"#include ""newres.h""\r\n"
"\0"
END
........
The above is .rc file.
Hope someone can explain that.
Thanks in advance
|
|
|
|
|
Hi,
This sounds like it might be related to code inline expansion. Where are you calling the function DrawInfoLabel() ? Are you calling this from the WM_PAINT handler?
Best Wishes,
-David Delaune
|
|
|
|
|
I call that function just in a general member function.
CTestDlg
{
public:
void refreshInfoLabel(void);
}
void CTestDlg::refreshInfoLabel(void)
{
DrawInfoLabel()
}
|
|
|
|
|
Hi,
It is generally not recommended to draw outside of the WM_PAINT/WM_ERASEBKGND handlers. When you draw outside of WM_PAINT you need to invalidate the window rectangle/region so that the subsystem knows to redraw it.
InvalidateRect function[^]
InvalidateRgn function[^]
Best Wishes,
-David Delaune
|
|
|
|
|
I wonder if WM_PAINT message handler could display messages immediately.
or even I draw it in a member function, it would refresh in OnPaint() executed?
|
|
|
|
|
econy wrote:
I wonder if WM_PAINT message handler could display messages immediately.
or even I draw it in a member function, it would refresh in OnPaint() executed?
No. There is no guarantee that when your WM_PAINT message fires that the subsystem will redraw window contents unless the rectangle/region/window is marked invalid. This is an OS optimization to prevent excessive redrawing. (However with DWM enabled[^] the rules do change a bit)
Read all of this so that in the future you can help others: Painting and Drawing[^]
Best Wishes,
-David Delaune
|
|
|
|
|
|
I am confused with SetFont() function.
I followed example code in MSDN, it works well in my laptop.
but, when I same code in my WinCE program, it dont work, font not change, show [] [] [] []
LOGFONT lf; CEdit *pEdit1;
lf.lfHeight = 12;
lf.lfWidth = 0;
memset(&lf, 0, sizeof(LOGFONT)); WCHAR lffn[] = TEXT("Simsun(OpenType)");
wcscpy(lf.lfFaceName,lffn);
lf.lfCharSet = GB2312_CHARSET;
if (m_font2.m_hObject) {
m_font2.DeleteObject();
}
m_font2.CreateFontIndirect(&lf);
pEdit1 = (CEdit *) GetDlgItem( IDC_EDIT1 );
pEdit1->SetFont(&m_font2);
SetDlgItemText(IDC_EDIT1, _T("公里") );
Appreciate any suggestions
|
|
|
|
|