Cerf
August 24th, 2005, 09:09 PM
Hey,
I am creating a dll that is used in one of my visual basic programs. The thread will just do some basic background calculations for me
#include "stdafx.h"
#include "vbThreaded.h"
#include <windows.h>
UINT CVbThreadedApp::ThreadFunc()
{
typedef void (__stdcall *FUNCPTR)(BSTR pbstr);
FUNCPTR vbFunc;
// Point the function pointer at the passed-in address.
vbFunc = (FUNCPTR)addr;
// Call the function through the function pointer.
vbFunc(SysAllocString(L"Threaded call"));
return 0;
}
extern "C" short PASCAL EXPORT thread(long cbAddress)
{
AFX_MANAGE_STATE(AfxGetStaticModuleState());
// normal function body here
/* typedef void (__stdcall *FUNCPTR)(BSTR pbstr);
FUNCPTR vbFunc;
// Point the function pointer at the passed-in address.
vbFunc = (FUNCPTR)cbAddress;
// Call the function through the function pointer.
vbFunc(SysAllocString(L"Hi! This message came from your DLL!"));
*/
addr = cbAddress;
PMYDATA pData;
// Allocate memory for thread data.
pData = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
sizeof(MYDATA));
pData->val1 = 1;
pData->val2 = 100;
hThread[i] = CreateThread(
NULL, // default security attributes
0, // use default stack size
ThreadFunc, // thread function
pData, // argument to thread function
0, // use default creation flags
&dwThreadId[i]); // returns the thread identifier
//myThread = AfxBeginThread(ThreadFunc,0);
return 0;
}
And since this is my first first threaded project I am getting some very newbist errors
--------------------Configuration: vbThreaded - Win32 Debug--------------------
Compiling...
vbThreaded.cpp
C:\Documents and Settings\Derek Shaw\Desktop\vbThreaded\vbThreaded.cpp(99) : error C2065: 'PMYDATA' : undeclared identifier
C:\Documents and Settings\Derek Shaw\Desktop\vbThreaded\vbThreaded.cpp(99) : error C2146: syntax error : missing ';' before identifier 'pData'
C:\Documents and Settings\Derek Shaw\Desktop\vbThreaded\vbThreaded.cpp(99) : error C2065: 'pData' : undeclared identifier
C:\Documents and Settings\Derek Shaw\Desktop\vbThreaded\vbThreaded.cpp(104) : error C2065: 'MYDATA' : undeclared identifier
C:\Documents and Settings\Derek Shaw\Desktop\vbThreaded\vbThreaded.cpp(104) : error C2440: '=' : cannot convert from 'void *' to 'int'
This conversion requires a reinterpret_cast, a C-style cast or function-style cast
C:\Documents and Settings\Derek Shaw\Desktop\vbThreaded\vbThreaded.cpp(106) : error C2227: left of '->val1' must point to class/struct/union
C:\Documents and Settings\Derek Shaw\Desktop\vbThreaded\vbThreaded.cpp(107) : error C2227: left of '->val2' must point to class/struct/union
C:\Documents and Settings\Derek Shaw\Desktop\vbThreaded\vbThreaded.cpp(109) : error C2065: 'hThread' : undeclared identifier
C:\Documents and Settings\Derek Shaw\Desktop\vbThreaded\vbThreaded.cpp(109) : error C2065: 'i' : undeclared identifier
C:\Documents and Settings\Derek Shaw\Desktop\vbThreaded\vbThreaded.cpp(109) : error C2109: subscript requires array or pointer type
C:\Documents and Settings\Derek Shaw\Desktop\vbThreaded\vbThreaded.cpp(112) : error C2065: 'ThreadFunc' : undeclared identifier
C:\Documents and Settings\Derek Shaw\Desktop\vbThreaded\vbThreaded.cpp(115) : error C2065: 'dwThreadId' : undeclared identifier
C:\Documents and Settings\Derek Shaw\Desktop\vbThreaded\vbThreaded.cpp(115) : error C2109: subscript requires array or pointer type
C:\Documents and Settings\Derek Shaw\Desktop\vbThreaded\vbThreaded.cpp(115) : error C2102: '&' requires l-value
Error executing cl.exe.
vbThreaded.obj - 14 error(s), 0 warning(s)
I tried using #include <strsafe.h> but the compiler just couldn't find the file (fatal error C1083: Cannot open include file: 'strsafe.h': No such file or directory)
I was just wondering if anyone could help me get back on my feet?
I am creating a dll that is used in one of my visual basic programs. The thread will just do some basic background calculations for me
#include "stdafx.h"
#include "vbThreaded.h"
#include <windows.h>
UINT CVbThreadedApp::ThreadFunc()
{
typedef void (__stdcall *FUNCPTR)(BSTR pbstr);
FUNCPTR vbFunc;
// Point the function pointer at the passed-in address.
vbFunc = (FUNCPTR)addr;
// Call the function through the function pointer.
vbFunc(SysAllocString(L"Threaded call"));
return 0;
}
extern "C" short PASCAL EXPORT thread(long cbAddress)
{
AFX_MANAGE_STATE(AfxGetStaticModuleState());
// normal function body here
/* typedef void (__stdcall *FUNCPTR)(BSTR pbstr);
FUNCPTR vbFunc;
// Point the function pointer at the passed-in address.
vbFunc = (FUNCPTR)cbAddress;
// Call the function through the function pointer.
vbFunc(SysAllocString(L"Hi! This message came from your DLL!"));
*/
addr = cbAddress;
PMYDATA pData;
// Allocate memory for thread data.
pData = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
sizeof(MYDATA));
pData->val1 = 1;
pData->val2 = 100;
hThread[i] = CreateThread(
NULL, // default security attributes
0, // use default stack size
ThreadFunc, // thread function
pData, // argument to thread function
0, // use default creation flags
&dwThreadId[i]); // returns the thread identifier
//myThread = AfxBeginThread(ThreadFunc,0);
return 0;
}
And since this is my first first threaded project I am getting some very newbist errors
--------------------Configuration: vbThreaded - Win32 Debug--------------------
Compiling...
vbThreaded.cpp
C:\Documents and Settings\Derek Shaw\Desktop\vbThreaded\vbThreaded.cpp(99) : error C2065: 'PMYDATA' : undeclared identifier
C:\Documents and Settings\Derek Shaw\Desktop\vbThreaded\vbThreaded.cpp(99) : error C2146: syntax error : missing ';' before identifier 'pData'
C:\Documents and Settings\Derek Shaw\Desktop\vbThreaded\vbThreaded.cpp(99) : error C2065: 'pData' : undeclared identifier
C:\Documents and Settings\Derek Shaw\Desktop\vbThreaded\vbThreaded.cpp(104) : error C2065: 'MYDATA' : undeclared identifier
C:\Documents and Settings\Derek Shaw\Desktop\vbThreaded\vbThreaded.cpp(104) : error C2440: '=' : cannot convert from 'void *' to 'int'
This conversion requires a reinterpret_cast, a C-style cast or function-style cast
C:\Documents and Settings\Derek Shaw\Desktop\vbThreaded\vbThreaded.cpp(106) : error C2227: left of '->val1' must point to class/struct/union
C:\Documents and Settings\Derek Shaw\Desktop\vbThreaded\vbThreaded.cpp(107) : error C2227: left of '->val2' must point to class/struct/union
C:\Documents and Settings\Derek Shaw\Desktop\vbThreaded\vbThreaded.cpp(109) : error C2065: 'hThread' : undeclared identifier
C:\Documents and Settings\Derek Shaw\Desktop\vbThreaded\vbThreaded.cpp(109) : error C2065: 'i' : undeclared identifier
C:\Documents and Settings\Derek Shaw\Desktop\vbThreaded\vbThreaded.cpp(109) : error C2109: subscript requires array or pointer type
C:\Documents and Settings\Derek Shaw\Desktop\vbThreaded\vbThreaded.cpp(112) : error C2065: 'ThreadFunc' : undeclared identifier
C:\Documents and Settings\Derek Shaw\Desktop\vbThreaded\vbThreaded.cpp(115) : error C2065: 'dwThreadId' : undeclared identifier
C:\Documents and Settings\Derek Shaw\Desktop\vbThreaded\vbThreaded.cpp(115) : error C2109: subscript requires array or pointer type
C:\Documents and Settings\Derek Shaw\Desktop\vbThreaded\vbThreaded.cpp(115) : error C2102: '&' requires l-value
Error executing cl.exe.
vbThreaded.obj - 14 error(s), 0 warning(s)
I tried using #include <strsafe.h> but the compiler just couldn't find the file (fatal error C1083: Cannot open include file: 'strsafe.h': No such file or directory)
I was just wondering if anyone could help me get back on my feet?