|
Exporting from a DLL Using __declspec(dllexport)[^]
Many export directives, such as ordinals, NONAME, and PRIVATE, can be made only in a .def file, and there is no way to specify these attributes without a .def file. However, using __declspec(dllexport) in addition to using a .def file does not cause build errors.
It's a protection scheme they are exported as privates or ordinals probably so they can avoid ANSI, MBCS, and Unicode issues on the call name.
In vino veritas
modified 25-Jan-18 0:07am.
|
|
|
|
|
|
My development environment is Eclipse C Android NDK
I want to create and run a Simple thread from a function
I am trying to use
pthread_create()
Can some one point me to a simple thread example C Android
What I tired and confusing for me is, what parms I need to pass to this function ?
JNIEXPORT void JNICALL
Java_org_testjni_android_Game_someFunction(JNIEnv * env, jobject obj)
{
|
|
|
|
|
What does the first part of your question have to do with the second? What thread are you trying to create and run? What is the JNI function for?
|
|
|
|
|
As Richard pointed out, there (should be) no need to export to the Java environment the pthread_create function. Make a wrapper (with a simpler signature) for that and then export to Java (if you need to) such a wrapper.
As about pthread_create , its very man page[^] provides sample code.
|
|
|
|
|
I'm using a class to work with the registry that I downloaded from an MSDN article. The problem is that whenever I go to read a string (REG_SZ), the RegGetValue call fails with ERROR_FILE_NOT_FOUND (#2).
In fact no matter what I've tried, it insists on returning that error. I've tried building the program for 64-bit as well as 32 - no difference. I've made sure that the key is being opened properly. That succeeds, but reading a string value does not. I'm now pulling my hair out.
Does anyone know why it's returning ERROR_FILE_NOT_FOUND?
This is the code that's calling RegGetValue:
inline std::wstring RegGetString(HKEY hKey, const std::wstring& subKey, const std::wstring& value)
{
DWORD dataSize{};
LONG retCode = ::RegGetValue(
hKey,
subKey.c_str(),
value.c_str(),
RRF_RT_REG_SZ,
nullptr,
nullptr,
&dataSize);
if (retCode != ERROR_SUCCESS)
{
throw RegistryError{ "Cannot read string from registry", retCode };
}
These are the relevant values: hKey is HKEY_CURRENT_USER,
subKey is "Software\Microsoft\Windows\CurrentVersion\Run" The string is properly escaped.
and value is a REG_SZ entry.
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|
|
Hmmmm,
Your code works for me. Here is how I am calling your function:
HKEY hKey;
DWORD dwResult = RegOpenKeyEx(HKEY_CURRENT_USER, nullptr, 0, KEY_READ, &hKey);
if (ERROR_SUCCESS == dwResult)
{
std::wstring subkey = L"Software\\Microsoft\\Windows\\CurrentVersion\\Run";
std::wstring value = L"OneDrive";
RegGetString(hKey, subkey, value);
}
RegCloseKey(hKey);
Best Wishes,
-David Delaune
|
|
|
|
|
Thank you for your response. The code you posted works for me too.
I notice that you opened the HKEY without specifying a subkey in the call to RegOpenKeyEx. You only specified the subkey in the call to RegGetString. Is that the way it's supposed to work? Should I not pass a subkey to RegOpenKeyEx?
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|
|
Richard,
Richard Andrew x64 wrote: I notice that you opened the HKEY without specifying a subkey in the call to RegOpenKeyEx. You only specified the subkey in the call to RegGetString. Is that the way it's supposed to work? Should I not pass a subkey to RegOpenKeyEx?
No.
Your sample code works even if I open the subkey in the call to RegOpenKeyEx.
HKEY hKey;
DWORD dwResult = RegOpenKeyEx(HKEY_CURRENT_USER, L"Software\\Microsoft\\Windows\\CurrentVersion\\Run", 0, KEY_READ, &hKey);
if (ERROR_SUCCESS == dwResult)
{
std::wstring subkey = L"Software\\Microsoft\\Windows\\CurrentVersion\\Run";
std::wstring value = L"OneDrive";
RegGetString(hKey, subkey, value);
}
RegCloseKey(hKey);
Your original bug is due to the fact that you are sending an empty string instead of a null pointer. Make the following change:
inline std::wstring RegGetString(HKEY hKey, const std::wstring& subKey, const std::wstring& value)
{
DWORD dataSize{};
LONG retCode = ::RegGetValue(
hKey,
nullptr, value.c_str(),
RRF_RT_REG_SZ,
nullptr,
nullptr,
&dataSize);
if (retCode != ERROR_SUCCESS)
{
int iDebug = 0;
}
return L"";
}
The MSDN documentation is poorly written. You should be following the rules described in the documentation for the RegOpenKeyEx function[^] lpSubKey parameter.
The lpSubKey parameter can be NULL only if hKey is one of the predefined keys. If lpSubKey is NULL and hKey is HKEY_CLASSES_ROOT, phkResult receives a new handle to the key specified by hKey. Otherwise, phkResult receives the same hKey handle passed in to the function.
Use the 'Is this Page Helpful' button at the bottom of the MSDN documentation for the RegGetValue function[^] and report the discrepancy.
Best Wishes,
-David Delaune
|
|
|
|
|
Thank you, David. I have it working now. You saved what's left of my hair.
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|
|
Are you sure that the string in value is correct?
|
|
|
|
|
Richard Andrew x64 wrote: I've tried building the program for 64-bit as well as 32 - no difference. I've made sure that the key is being opened properly. That succeeds, but reading a string value does not. I'm now pulling my hair out.
Well, how did you try with "building the program for 64-bit as well as 32"? Did you use the RRF_SUBKEY_WOW6464KEY and RRF_SUBKEY_WOW6432KEY flags? Or somehow else?
Also it would be not bad to see how exactly you call this RegGetString function.
|
|
|
|
|
Good Morning Ladies and Gentlemen!
I need help with my first script ever, being created in AutoHotKey. I hope that I am posting this in the right forum, considering it seems close to C++ language. I do apologize for my ignorance. I am trying to write a script to work on a non-active windowed game, while I am spawning with another character in a separate window. This is my first script, so all the help I can get would be greatly appreciated. I am willing to pay you for a full working script to do the functions I like. The functions are as followed, I need the script to spell my character up, which includes hitting multiple F-Keys and then clicking my character to apply for most, some are automatically casted when clicked, applying to the character itself. Secondly, I need it to hold down the F4 key to spam a AOE spell also for atleast 10min. After spelling up, before casting the AOE, and or before the spellup, I need to Hit the F3 key, which is a manastone filling my mana bar for magic use. I need this to loop itself continuously and have a start and a stop to the script. Please see below what I have and let me know where I went wrong. It is not finished, just kind of a idea. Please see below, not finished, stumped currently.
#SingleInstance, force
#If WinExist, ""
setKeyDelay, 10, 10
setMouseDelay, 10
`::
Loop {
Send, F3
Sleep, 100 ; ------------------- optional extra sleep timer
Send, F6
Sleep, 100
Send, F8
Sleep, 100
Send, F10
Sleep, 100
Click 0,0 ;These are the coords
Sleep, 100
Send, F11 ; ----- If doesnt work use ;ControlSend {F11}
Sleep, 100
Click, 0,0 ; ----- If doesnt work use ;ControlClick, x# y#, ahk_class <name>, , Left, #oftimes, NA
Sleep, 100
Send, F12
Sleep, 100
Send, {F4 down}
Sleep, 10000 ;ten minutes
Send, {F4 up}
}
Return
; all loops should have some emergency pause, suspend or exit key
Esc::
Pause
|
|
|
|
|
ThatOldGuy wrote: it seems close to C++ language. Not even remotely so. The correct forum would obviously be The autohotkey forums[^]
|
|
|
|
|
Richard,
I'm sorry brother, did not see that forum when I searched through the different ones. Can this possibly be moved to there?
|
|
|
|
|
No, it can't. Posts can not be moved between unrelated forums.
|
|
|
|
|
It wasn't exactly hard to find; all I did was type "AutoHotkey" into Google.
|
|
|
|
|
Rick,
I misunderstood you, I thought you meant it was a group on this forum. Unfortunately that forum is not really active, and I have tried to ask there. Do you think you could, or would be able to take on a task like this?
Thank You
ThatOldGuy
|
|
|
|
|
ThatOldGuy wrote: Do you think you could, or would be able to take on a task like this? Sorry, I have no idea what AutoHotKey is, or what it is supposed to do; that's why I pointed you to their website.
|
|
|
|
|
Rick,
Ok, no worries. I appreciate the response.
Thank You
|
|
|
|
|
Hello,
I am trying to make a program in C with multiple bouncing balls. The problem is that I have created a code, but my program doesn’t run properly. To be more exact, I think the part where it reads the data is fine, but then there is a problem in the code of the graphics.h library. I cannot understand where the problem is, as it is the first time I use this library.
Thank you in advamce.
Here is my code:
#include <stdio.h>
#include <graphics.h>
#include <stdlib.h>
#include <time.h>
#include <math.h>
int main()
{
FILE *input;
int n, *num, i, total, j;
if((input=fopen("data.txt", "r"))!=NULL)
{
fscanf(input, "%d", &n);
total=n*7;
num=(int *) malloc(total*sizeof(int));
if(num!=NULL)
{
for(i=0; i<total; i++)
{
fscanf(input, "%d", &num[i]);
}
fclose(input);
clock_t start,finish, previous;
double step;
int gdriver = DETECT, gmode, errorcode;
initgraph(&gdriver, &gmode, "");
errorcode = graphresult();
if (errorcode != grOk)
{
printf("Graphics error: %s\n", grapherrormsg(errorcode));
system ("pause");
exit(1);
}
start=clock();
previous=start;
do
{
j=0;
for(i=0; i<=n; i++)
{
finish = clock();
step = (finish-previous)*1.0/CLOCKS_PER_SEC;
if (step >= 0.03)
{
previous = finish;
setfillstyle(SOLID_FILL,BLACK);
setcolor(BLACK);
fillellipse(num[j],num[j+1],num[j+4],num[j+4]);
num[j]+= num[j+5]*step;
num[j+1]+= num[j+6]*step;
if (num[j]+num[j+4]>=getmaxx() || num[j]-num[j+4]<=0)
{
num[j+5] *= -1;
}
if (num[j+1]+num[j+4]>=getmaxy() || num[j+1]-num[j+4]<=0)
{
num[j+6] *= -1;
}
setfillstyle(SOLID_FILL,RED);
setcolor(RED);
fillellipse(num[j],num[j+1],num[j+4],num[j+4]);
j=j+7;
}
}
}
while (!kbhit());
closegraph();
}
else
{
printf("Could not allocate memory\n\n");
}
}
else
{
printf("Could not open file\n\n");
}
system("pause");
return 0;
}
|
|
|
|
|
Member 13632263 wrote: my program doesn’t run properly You need to provide more exact details than that, as we have no idea what you are seeing when you run it. It has to be said that these libraries are a throwback from the old days of MS-DOS and may not work correctly under Windows. See How to use graphics.h in visual C++ 2012?[^].
|
|
|
|
|
When I run it it just shows the Windows error that the program stopped working, so I have to close it.
|
|
|
|
|
I am afraid that information tells us nothing. You need to run your code in the debugger which will help you to find out exactly where it is stopping. But, as I already said, this library is very old and may not work under Windows.
|
|
|
|
|
I have seen similar projects which ran very good. Here is what it shows after the debugging:
https://mega.nz/#!NRwEAJKR!KI5cTeFhAaagIaRlbBoba1ugKt1j2RYEgUkF4lc8Atc
|
|
|
|
|