I am working on a namespace extension project, I need to implement multiple files drag and drop between Namespace Extensions. I have used DragQueryFile API to find the the number of files. But Always this Function give a crash.
Could anyone help me by explaining how we can implement this multiple files Drag and drop.
Thanks,
Robin
Here is how I use it
void yourclass::OnDropFiles(HDROP hDropInfo)
{
TCHAR lpszFile[MAX_PATH] = { 0 };
UINT uFile = 0;
uFile = DragQueryFile(hDropInfo, 0xFFFFFFFF, NULL, NULL);
if (uFile != 0)
{
for (int i = 0; i < uFile; i++)
{
lpszFile[0] = '\0';
if (DragQueryFile(hDropInfo, i, lpszFile, MAX_PATH))
{
std::wstring directory;
std::wstring filename;
LVITEM lvi = { 0 };
lvi.mask = LVIF_TEXT | LVIF_IMAGE | LVIF_PARAM;
SplitPath(lpszFile, directory, filename);
lvi.iSubItem = 0;
lvi.pszText = LPSTR_TEXTCALLBACK;
lvi.cchTextMax = MAX_PATH;
int n = m_wndFileList.InsertItem(&lvi);
m_wndFileList.SetItemText(n, 0, filename.c_str());
m_wndFileList.SetItemText(n, 1, directory.c_str());
}
}
}
DragFinish(hDropInfo);
return;
CDialogEx::OnDropFiles(hDropInfo);
}
Related
Given this code:
void CSelectNamesDlg::ShuffleArray(CString strName, CStringArray *pAryStrNames)
{
if (pAryStrNames == nullptr)
return;
const auto iSize = pAryStrNames->GetSize();
if (iSize > 1)
{
// First, we must locate strName in the array
auto i = CSelectNamesDlg::LocateText(strName, pAryStrNames);
if (i != -1)
{
const auto iName = i;
// We must now shuffle the names from the bottom to the top
const auto iCount = gsl::narrow<int>(iSize) - iName;
for (i = 0; i < iCount; i++)
{
CString strTemp = pAryStrNames->GetAt(iSize-1);
pAryStrNames->RemoveAt(iSize-1);
pAryStrNames->InsertAt(0, strTemp);
}
}
}
}
int CSelectNamesDlg::LocateText(CString strText, const CStringArray *pAryStrText)
{
bool bFound = false;
int i{};
if (pAryStrText != nullptr)
{
const auto iSize = pAryStrText->GetSize();
for (i = 0; i < iSize; i++)
{
if (pAryStrText->GetAt(i) == strText)
{
// Found him!
bFound = true;
break;
}
}
}
if (!bFound)
i = -1;
return (int)i;
}
If I convert my CStringArray into a std::vector<CString is it going to be simpler to achieve the same PerformShuffle and LocateText methods?
Should I just stay with CStringArray?
I know of 1 (ONE!) benefit of MFC array over std::vector - they support MFC-style serialization. If you use it - you may be stuck.
However, if you don't - I would use std::vector<CString>. Your LocateText (that is overly verbose) will become obsolete - just use find
Also, your ShuffleArray is very inefficient (remove/insert one item at a time). Using a vector will allow you to do something like Best way to extract a subvector from a vector?
So, I create this map on the fly so I can update the image type for all the images in the library (currently over 1 million). The map populates well, HOWEVER, despite visually seeing the extension ("jpg") added to the map, std::map::find("jpg") == std::map::end() always. What gives.
void CImageLibrary::ThreadedUpdateImageLibraryFileDuringOpen(shared_ptr<ScanData> pScanData)
{
size_t nCount = pScanData->GetImageLibrary()->m_imageEntries.count();
std::map<std::wstring, CImageType *> mapImageExtToType;
for (const auto &pImageType : pScanData->GetImageLibrary()->m_vecImageTypes)
{
std::vector<std::wstring> vecExtensions;
pImageType->GetAssociatedExtensions(vecExtensions);
for (auto ext : vecExtensions)
{
std::transform(ext.begin(), ext.end(), ext.begin(), ::tolower);
mapImageExtToType[ext] = pImageType;
}
}
for (size_t idx = 0; idx < nCount; ++idx)
{
CImageEntry *pEntry = pScanData->GetImageLibrary()->m_imageEntries[idx];
if (pEntry && !pEntry->GetImageType())
{
wstring &wsPath = pEntry->GetPathName(), wsExt;
size_t nIdx = wsPath.find_last_of('.');
wsExt = wsPath.substr(nIdx + 1);
std::transform(wsExt.begin(), wsExt.end(), wsExt.begin(), ::tolower);
auto Itor = mapImageExtToType.find(wsExt);
if (Itor == mapImageExtToType.end())
pEntry->m_pImageType = nullptr;
else
pEntry->m_pImageType = Itor->second;
}
}
pScanData->GetBkgndThreadManager()->MarkOperationThreadDone(std::this_thread::get_id());
}
I have some problems with splitting the file and I don't know what to do now. I have to split the movie and then merge the splited elements into one. And i have to use FileStream. If you can help me, i will be really happy :)
using System;
using System.Collections.Generic;
using System.IO;
class Program
{
static void Main()
{
string source = "../../movie.avi";
string destination;
int n = int.Parse(Console.ReadLine());
for (int i = 0; i < n; i++)
{
destination = "Part-" + i +".avi";
Slice(source, destination, n);
}
List<int> files = new List<int>();
//Assemble(, destination);
}
static void Slice(string sourceFile, string destinationDirectory, int parts)
{
using (var source = new FileStream(sourceFile, FileMode.Open))
{
for (int i = 0; i < parts; i++)
{
using (var destination = new FileStream(destinationDirectory, FileMode.CreateNew))
{
double fileLength = source.Length;
byte[] buffer = new byte[4096];
while (true)
{
int readBytes = source.Read(buffer, 0, buffer.Length);
if (readBytes == 0)
{
break;
}
destination.Write(buffer, 0, readBytes);
}
}
}
}
}
static void Assemble(List<string> files, string destinationDirectory)
{
}
}
All,
Currently i'm using Anviz EP300 time attendance machine. I need to download only new records from device.
I'm using following sdk. Click here
There is some method already have in sdk. Which is i used like...
int i = 0;
int Ret = 0;
int RecordCount = 0;
int RetCount = 0;
int pClockings = 0;
int pLongRun = 0;
CKT_DLL.CLOCKINGRECORD clocking = new CKT_DLL.CLOCKINGRECORD();
clocking.Time = new byte[20];
int ptemp = 0;
ProgressBar1.Value = 0;
//If CKT_GetClockingNewRecordEx(IDNumber, pLongRun) Then 'IF GET NewRecord
if (CKT_DLL.CKT_GetClockingNewRecordEx(IDNumber, ref pLongRun) != 0) //IF GET Record
{
while (true)
{
Ret = CKT_DLL.CKT_GetClockingRecordProgress(pLongRun, ref RecordCount, ref RetCount, ref pClockings);
if (RecordCount > 0)
{
ProgressBar1.Maximum = RecordCount;
}
if (Ret == 0)
{
return;
}
if (Ret != 0)
{
ptemp = pClockings;
for (i = 1; i <= RetCount; i++)
{
PCopyMemory(ref clocking, pClockings, CKT_DLL.CLOCKINGRECORDSIZE);
pClockings = pClockings + CKT_DLL.CLOCKINGRECORDSIZE;
insertTimeAttendance(clocking.PersonID, clocking.Stat, Encoding.Default.GetString(clocking.Time), clocking.ID);
ProgressBar1.Value += 1;
}
if (ptemp != 0)
{
CKT_DLL.CKT_FreeMemory(ptemp);
}
}
if (Ret == 1)
{
return;
}
}
}
CKT_GetClockingNewRecordEx that method should be return new records. But it returns all records.
I guess, there is should be one method or config should be mark as downloaded.
Anyone some idea or solution?
Thanks,
Eba
I created the SDK you downloaded (basically written in Vb, and I just convert it to C#)
Actually for the Anviz EP300 device, there is no way you can just retrieve new records,neither retrieve user lists (for example), at list with that SDK.. It has a lot of methods, but unfortunately few of them works fine. You will have to Use CKT_GetClockingRecordEx, instead of CKT_DLL.CKT_GetClockingNewRecordEx
I wrote a solution that involved OpenProcess, EnumProcessModules, GetModuleInformation and GetModuleBaseName, but apparently EnumProcessModules and GetModuleBaseName do not exist in Windows CE! What alternative is there?
I found a way to do this with CreateToolhelp32Snapshot, Module32First, Module32Next, Process32First and Process32Next. First you have to get a list of modules, then search through the list of modules to find the desired address.
#include <Tlhelp32.h>
struct MyModuleInfo
{
BYTE* Base;
HMODULE Handle;
DWORD Size;
enum { MaxNameLen = 36 };
TCHAR Name[MaxNameLen];
};
bool GetModuleList(vector<MyModuleInfo>& moduleList)
{
HANDLE hSnapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS | TH32CS_SNAPMODULE | TH32CS_GETALLMODS, 0);
if (hSnapshot == INVALID_HANDLE_VALUE)
return false;
MODULEENTRY32 moduleInfo;
moduleInfo.dwSize = sizeof(moduleInfo);
if (Module32First(hSnapshot, &moduleInfo)) do {
MyModuleInfo myInfo;
myInfo.Handle = moduleInfo.hModule;
myInfo.Base = moduleInfo.modBaseAddr;
myInfo.Size = moduleInfo.modBaseSize;
memcpy(myInfo.Name, moduleInfo.szModule, min(sizeof(myInfo.Name), sizeof(moduleInfo.szModule)));
myInfo.Name[myInfo.MaxNameLen-1] = '\0';
moduleList.push_back(myInfo);
} while (Module32Next(hSnapshot, &moduleInfo));
// The module list obtained above only contains DLLs! To get the EXE files
// also, we must call Process32First and Process32Next in a loop.
PROCESSENTRY32 processInfo;
processInfo.dwSize = sizeof(processInfo);
if (Process32First(hSnapshot, &processInfo)) do {
MyModuleInfo myInfo;
myInfo.Handle = NULL; // No handle given
myInfo.Base = (BYTE*)processInfo.th32MemoryBase;
myInfo.Size = 0x800000; // No size provided! Allow max 8 MB
memcpy(myInfo.Name, processInfo.szExeFile, min(sizeof(myInfo.Name), sizeof(processInfo.szExeFile)));
myInfo.Name[myInfo.MaxNameLen-1] = '\0';
moduleList.push_back(myInfo);
} while(Process32Next(hSnapshot, &processInfo));
// Debug output
for (int i = 0; i < (int)moduleList.size(); i++) {
MyModuleInfo& m = moduleList[i];
TRACE(_T("%-30s: 0x%08x - 0x%08x\n"), m.Name, (DWORD)m.Base, (DWORD)m.Base + m.Size);
}
CloseToolhelp32Snapshot(hSnapshot);
return true;
}
const MyModuleInfo* GetModuleForAddress(vector<MyModuleInfo>& moduleList, void* address)
{
for (int m = 0; m < (int)moduleList.size(); m++) {
const MyModuleInfo& mInfo = moduleList[m];
if (address >= mInfo.Base && address < mInfo.Base + mInfo.Size)
return &mInfo;
}
return NULL;
}