473,387 Members | 1,693 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Access violation writing error

I am getting the following error from my code:

Traceback (most recent call last):
File "<pyshell#309>", line 1, in <module>
get_handles('Python26')
File "C:\Python26\e__handle.py", line 19, in get_handles
ctypes.windll.user32.EnumWindows(ctypes.c_long(fun ction),ctypes.byref(ctypes.c_char_p(arg)))
WindowsError: exception: access violation writing 0x0064BCF6

From some searching online I think it's because I'm not able to properly pass the function's address pointer.
Expand|Select|Wrap|Line Numbers
  1. from e__handle import EnumWindowsProc, EnumChildWindowsProc
  2. import ctypes
  3. global listed
  4. global parents
  5. listed=[]
  6.  
  7. arg=str(parent_search_text)+'|'+str(parent_case_sensitive)+'|'+str(document)+'|'+str(child_search_text)+'|'+str(child_case_sensitive)+'|'+str(get_children)+'|'+str(id(EnumChildWindowsProc))
  8. function=id(EnumWindowsProc)
  9.  
  10. ctypes.windll.user32.EnumWindows(ctypes.c_long(function),ctypes.byref(ctypes.c_char_p(arg)))
  11. if document==True:
  12.     return listed
  13. else:
  14.     listed=[]
So the jist of the code is that I have defined EnumWindowsProc further down. I import the function so now it should be associated with an memory location. I use id(EnumWindowsProc) to get the address, but when I try to make it a pointer the pointer ends up referencing the location of the integer and not the function. Please let me know if this isn't clear.

I changed the one line to
ctypes.windll.user32.EnumWindows(ctypes.POINTER(fu nction),ctypes.byref(ctypes.c_char_p(arg)))

and got a different error of:
Traceback (most recent call last):
File "<pyshell#311>", line 1, in <module>
get_handles('Python26')
File "C:\Python26\e__handle.py", line 17, in get_handles
ctypes.windll.user32.EnumWindows(ctypes.POINTER(fu nction),ctypes.byref(ctypes.c_char_p(arg)))
TypeError: must be a ctypes type

Any ideas?
Aug 14 '09 #1
3 8338
I was able to use ctypes.pointer instead of ctypes.POINTER for the following:
ctypes.pointer(ctypes.c_int(id(function name)))

However, now I'm getting a different error that gets triggered on the line that calls the EnumWindows function

Expand|Select|Wrap|Line Numbers
  1. from e__handle import EnumWindowsProc, EnumChildWindowsProc
  2. import ctypes
  3. global listed
  4. global parents
  5. listed=[]
  6. arg=str(parent_search_text)+'|'+str(parent_case_sensitive)+'|'+str(document)+'|'+str(child_search_text)+'|'+str(child_case_sensitive)+'|'+str(get_children)+'|'+str(id(EnumChildWindowsProc))
  7. function_pntr=ctypes.pointer(ctypes.c_long(id(EnumWindowsProc)))
  8. ctypes.windll.user32.EnumWindows(function_pntr,ctypes.byref(ctypes.c_char_p(arg)))
  9. if document==True:
  10.     return listed
  11. else:
  12.     listed=[]
Traceback (most recent call last):
File "<pyshell#1>", line 1, in <module>
get_handles('Python26')
File "C:\Python26\e__handle.py", line 17, in get_handles
ctypes.windll.user32.EnumWindows(function_pntr,cty pes.byref(ctypes.c_char_p(arg)))
WindowsError: exception: access violation writing 0x006917E0

I have also received the following error after restarting the Python Shell:

Traceback (most recent call last):
File "<pyshell#5>", line 1, in <module>
get_handles('Python26')
File "C:\Python26\e__handle.py", line 18, in get_handles
ctypes.windll.user32.EnumWindows(function_pntr,cty pes.c_char_p(arg))
WindowsError: exception code 0xc000001e

but then it went back to the first error.

Is there a way of determining if I'm not calling the EnumWindows function correctly?
Aug 14 '09 #2
Okay, so it turns out that I was not using the correct type to pass to the function. I ended up using:

function_ptr=WINFUNCTYPE(c_int,c_int,c_int)
then calling the EnumWindows function like this:
ctypes.windll.user32.EnumWindows(function_ptr(function name),argument)

(a good example can be found at http://bytes.com/topic/python/answer...og-box-removal)

The above code now correctly calls the function, however, there is still something I need help with...

I am attempting to pass a string through the EnumWindows function call to my defined function. The problem I'm having is that all that shows up to my user defined function is an integer. I'm thinking it's because it's passing a reference or pointer to the variable instead of the value itself.

Is there a ctypes function or method that I haven't found yet that will take the pointer value and allow me to attach it to a ctypes object (like c_char_p, which is how it is being sent)?
Aug 15 '09 #3
I think I will mark this particular thread as being solved and start a new thread for the new issue I need help with.
Aug 17 '09 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

15
by: Steven Reddie | last post by:
I understand that access violations aren't part of the standard C++ exception handling support. On Windows, a particular MSVC compiler option enables Microsoft's Structured Exception Handling...
11
by: muser | last post by:
In the code I supplied before this one, the cause of the problem is an access violation error. When I run the debugger it skips into what I can only assume is the compilers version of my code. And...
0
by: Steven Reddie | last post by:
In article <slrnbnj19j.av.juergen@monocerus.manannan.org>, Juergen Heinzl wrote: >In article <f93791bd.0309282133.650da850@posting.google.com>, Steven Reddie wrote: >> I understand that access...
0
by: Microsoft News | last post by:
I'm getting the following error when I shut down my C# .NET v1.1 application: 0xC0000005: Access violation reading location 0x73bc0000 This error didn't occur until I added a...
1
by: Yanping Zhang | last post by:
Here are more details about my codes, please help! The function declared in C: typedef void (WINAPI *PLEARNCALLBACKPROC) (unsigned int progress, unsigned int sigQuality, unsigned long...
1
by: =?Utf-8?B?c2F0aGVlc2t1bWFy?= | last post by:
In my project i have a component named PTS Engine which is developed in VC++ ..Net 2003. And it is migrated to VC++.NET 2005 version. Initially this migration process has coded and tested in VC++...
2
by: =?Utf-8?B?c29jYXRvYQ==?= | last post by:
Hi, I have a DLL in VC6, when a specific function is called it will spawns a few threads and then return. The threads stay running and inside one of these threads an event is created using the...
39
by: Martin | last post by:
I have an intranet-only site running in Windows XPPro, IIS 5.1, PHP 5.2.5. I have not used or changed this site for several months - the last time I worked with it, all was well. When I tried it...
0
by: trayres | last post by:
Hi all! I'm trying to use ctypes to access a function in a DLL. Here is the function prototype: extern "C" void__stdcall__declspec(dllexport) ReturnPulse(double*,double*,double*,double*,double*); ...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.